Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
State Dropdown not showing in create account
 
InitechDesign
Sr. Member
 
Total Posts:  88
Joined:  2008-11-12
 

I wanted all of the address information to show on the “Create an Account” page so I am able to collect all of the customers info before approving their account for wholesale.

I found a post with instructions of where I could edit… app/design/frontend/default/default/template/customer/form/register.phtml and remove the code below to make the address info show.

<?php if($this->getShowAddressFields()): ?>
and
<?php endif; ?>

The address info shows up now but the drop down box for the state isn’t there. Here is a link to the create an account page.  https://www.cardcubby.com/wholesale/customer/account/create/

Anyone know of a better way to achieve what I am trying to do or how to fix this issue???

 
Magento Community Magento Community
Magento Community
Magento Community
 
zinferro
Jr. Member
 
Total Posts:  15
Joined:  2009-01-01
 

Hi!
Do you see that line:

<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none">

remove style="display:none”, you will see the drop down.

Gud luck!

 
Magento Community Magento Community
Magento Community
Magento Community
 
InitechDesign
Sr. Member
 
Total Posts:  88
Joined:  2008-11-12
 

Well I removed the “Display none” from the first part of the code and that made it show up but none of the states are showing. Here is the code for that area.

<div class="input-box">
                    <
label for="region_id"><?php echo $this->__('State/Province'?> <span class="required">*</span></label><br />
                    <
select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select">
                        <
option value=""><?php echo $this->__('Please select region, state or province'?></option>
                    </
select>
                    <
script type="text/javascript">
                        $(
'region_id').setAttribute('defaultValue',  "<?php echo $this->getFormData()->getRegionId() ?>");
                    
</script>
                    
<input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none" />
                </
div>

Any ideas???

 
Magento Community Magento Community
Magento Community
Magento Community
 
InitechDesign
Sr. Member
 
Total Posts:  88
Joined:  2008-11-12
 

If I remove the “Display none” on the second part of that code and added it back to the first part of the code would they be able to manually enter their state. I would try this myself but it’s on a live site with a lot of visitors right now........

or does anyone else know how to make the states show up???

 
Magento Community Magento Community
Magento Community
Magento Community
 
zinferro
Jr. Member
 
Total Posts:  15
Joined:  2009-01-01
 

Uhm, It’s not impossible to do that, but the database of Magento just has the regions of some countries, such as US, CA, DT, FR.... If you want to display them, you must write some scripts in the “onchange()” event of country select box (when user change the country, the state /province will be changed , correlated with the country),
You can consult my solution:
- display the US state/province:
+ replace this:

<div class="input-box">
                    <
label for="region_id"><?php echo $this->__('State/Province'?> <span class="required">*</span></label><br />
                    <
select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select">
                        <
option value=""><?php echo $this->__('Please select region, state or province'?></option>
                    </
select>
                    <
script type="text/javascript">
                        $(
'region_id').setAttribute('defaultValue',  "<?php echo $this->getFormData()->getRegionId() ?>");
                    
</script>
                    
<input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none" />
</
div>
by this:
<div class="input-box">
                    <
label for="region_id"><?php echo $this->__('State/Province'?> <span class="required">*</span></label><br />
                    <
select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>">
                        <
option value="0"><?php echo $this->__('Please select region, state or province'?></option>
                        
<?php
                        $this
->setData('country_id','US'); // or 'FR'..., default is 'US'
                        
$regions     =   $this->getRegionCollection();
                        foreach(
$regions as $region)
                        
{
                            
echo "<option value=$region[region_id]>".$region['name'"</option>";
                        
}
                        ?>
                    
</select>  
                    <
script type="text/javascript">
                        $(
'region_id').setAttribute('defaultValue',  "<?php echo $this->getFormData()->getRegionId() ?>");
                    
</script>
                    
<input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" />
                </
div>
+ if the user is not in US, he/she can input their choice in the textbox.

- If you want the state/province to auto-change when the country changed, you can write some AJAX code to do this. (now I have not much time, so you can try yourself:D ), use that function to change the country_code when user changes the country:

$this->setData('country_id','US'); // replace 'US' by 'FR'.,or something.., default is 'US'

then getRegionCollection() to print out the state/province.

Hope it can help you. wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
5erTag
Member
 
Total Posts:  46
Joined:  2008-04-08
 

Hi,

i´m using 1.3.1, and enabeling the whole Data form with the working region_id field is quite easy:

in the “register.phtml” delete or comment out the line:

<?php if($this->getShowAddressFields()): ?>

and also <?php endif; ?>

then go to .....template/customer/address/edit.phtml

and copy the javascript snippet at the end of the file, because it changed, or use this and overwrite the script at the end of register.phtml

New script from edit.phtml:

<script type="text/javascript\">
var dataForm = new VarienForm(’form-validate’, true);
new RegionUpdater(’country’, ‘region’, ‘region_id’, <?php echo $this->helper('directory')->getRegionJson() ?>);
</script>

--------------
no warranty, so safe, backup often and early, before changing anything grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
InitechDesign
Sr. Member
 
Total Posts:  88
Joined:  2008-11-12
 
5erTag - 28 May 2009 02:01 AM

Hi,

i´m using 1.3.1, and enabeling the whole Data form with the working region_id field is quite easy:

in the “register.phtml” delete or comment out the line:

<?php if($this->getShowAddressFields()): ?>


and also <?php endif; ?>

then go to .....template/customer/address/edit.phtml

and copy the javascript snippet at the end of the file, because it changed, or use this and overwrite the script at the end of register.phtml

New script from edit.phtml:

<script type="text/javascript\">
var dataForm = new VarienForm(’form-validate’, true);
new RegionUpdater(’country’, ‘region’, ‘region_id’, <?php echo $this->helper('directory')->getRegionJson() ?>);
</script>

I tried what you were talking about with the edit.phtml script but that didn’t make the states show up. I was assuming I needed to change the “display: none” and that made the box show up but there are no states in it. Can you explain what you were referring to when you said “enabling the whole Data form with the working region_id field”

 
Magento Community Magento Community
Magento Community
Magento Community
 
andrewherman
Jr. Member
 
Total Posts:  19
Joined:  2009-06-14
 

To recap, for Version 1.3.2.1

Step 1: delete/comment out

<?php if($this->getShowAddressFields()): ?>
and
<?php endif; ?>
so theyll look like
<?php // if($this->getShowAddressFields()): ?>
and
<?php // endif; ?>

step 2: delete or comment out the “ style="display:none" ‘ from the code. It occurs both for the line that begins with

"select id="region_id" name="region_id"
and for the line that begins with
<input type="text" id="region"
There doesnt seem to be a noticable difference between deleting only the first or deleting both instances.

step 3: at the bottom of the script, replace the commented out CDATA, which looks like this

<script type="text/javascript">
//the CDATA box was commented out earlier
<![CDATA[
    
var dataForm = new VarienForm('form-validate'true);
    
<?php if($this->getShowAddressFields()): ?>
    
new RegionUpdater('country''region''region_id'<?php echo $this->helper('directory')->getRegionJson() ?>);
    
<?php endif; ?>
]]
>
</script>

with

<script type="text/javascript\">
var 
dataForm = new VarienForm(’form-validate’true);
new 
RegionUpdater(’country’‘region’‘region_id’<?php echo $this->helper('directory')->getRegionJson() ?>);
</script>

Works fine now.

BONUS If you want the company name to be a required field instead of optional, replace

<div class="input-box">
                    <
label for="company"><?php echo $this->__('Company'?></label><br />
                    <
input type="text" name="company" id="company" value="<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text" />
                </
div>

with

<div class="input-box">
                    <
label for="company"><?php echo $this->__('Company'?> <span class="required">*</span></label><br />
                    <
input type="text" name="company" id="company" value="<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="required-entry input-text" />
                </
div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
j2tdesign
Sr. Member
 
Avatar
Total Posts:  208
Joined:  2008-07-16
France
 

I think that the easiest way is to put

<?php $this->setShowAddressFields(true)?>
Right before your if
 
Magento Community Magento Community
Magento Community
Magento Community
 
robertjohn
Member
 
Total Posts:  60
Joined:  2009-07-24
 

I have followed this but for some reason the state/province filed box fdoes not show.

Any ideas guys?

Thanks

RJ

Image Attachments
Picture 7.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
robertjohn
Member
 
Total Posts:  60
Joined:  2009-07-24
 

OK so as the weeks went by I have worked out by searching through the forum and by sheer guesswork, how to make my registration page work for me with required and non required fields behaving and looking good.

However none of the changes I made to register.phtml seem to have made any difference to the ‘checkout address’ form / customer ‘add new address’ form.  Do these forms work from a different file or files somehwere else where I will have to duplicate the changes I made to register.phtml in oder for them to work here also?

Please please somebody help.  This is delaying the launch of my site.

Screenshots attached again.

First picture: shows revised and working registration page (modern theme)
Second picture: shows ‘add new address’ form - changes to register.phtml having made no effect at all.

Lastly - what is the function of address.phtml?  Altering this - in fact deleting this file makes no difference to function of the site as far as I can see!!!

RJ

Image Attachments
mysite1.pngmysite2.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
Arif ul hoque
Jr. Member
 
Total Posts:  7
Joined:  2009-04-01
53, Jahan Cottage, (1st Floor), Mohammadpur Housig
 

Yes, in Magento ver. 1.3.2.3 the following code working. I just add $this->setShowAddressFields(true); before <?php if($this->getShowAddressFields()): ?>

Like as follows

<?php $this->setShowAddressFields(true); ?>
<?php if($this->getShowAddressFields()): ?>

Thanks everybody.

 
Magento Community Magento Community
Magento Community
Magento Community
 
robertjohn
Member
 
Total Posts:  60
Joined:  2009-07-24
 

OK so I have been away and have just got back to sorting this out.

I did as suggested and added code as Saskia suggested at correct place BUT When United Kingdom is selected there is STILL no drop down box of counties (states if l you prefer that description) so my customers in the UK still have to add their county/state details manually.  Drop down box works great for US, Switzerland, Germany, etc but nothing for UK!  Surely there must be a way to show not only a drop down box for UK but also the counties/states or at least a way to add states so that they are selectable from drop down box.

If counties/states are not included in the stock magento databse then they should be ad if not then please could somebody show me how to add them.

Hope I am explaining myself here.  How have other UK users managed?

cheers

RJ

 
Magento Community Magento Community
Magento Community
Magento Community
 
rodrigo423
Member
 
Total Posts:  32
Joined:  2009-03-18
 

<script type="text/javascript\">
var dataForm = new VarienForm(’form-validate’, true);
<?php //if($this->getShowAddressFields()): ?>
new RegionUpdater(’country’, ‘region’, ‘region_id’, <?php echo $this->helper('directory')->getRegionJson() ?>);
<?php //endif ?>
</script>

Worked! Big 5 for him!

 
Magento Community Magento Community
Magento Community
Magento Community
 
nemosreef
Jr. Member
 
Total Posts:  13
Joined:  2010-10-04
 
5erTag - 28 May 2009 02:01 AM

Hi,

i´m using 1.3.1, and enabeling the whole Data form with the working region_id field is quite easy:

in the “register.phtml” delete or comment out the line:

<?php if($this->getShowAddressFields()): ?>


and also <?php endif; ?>

then go to .....template/customer/address/edit.phtml

and copy the javascript snippet at the end of the file, because it changed, or use this and overwrite the script at the end of register.phtml

New script from edit.phtml:

<script type="text/javascript\">
var dataForm = new VarienForm(’form-validate’, true);
new RegionUpdater(’country’, ‘region’, ‘region_id’, <?php echo $this->helper('directory')->getRegionJson() ?>);
</script>



--------------
no warranty, so safe, backup often and early, before changing anything grin

worked great!! BUT with a typo “<script type="text/javascript\">" should be <script type="text/javascript\"

 
Magento Community Magento Community
Magento Community
Magento Community
 
K_R_P
Jr. Member
 
Total Posts:  9
Joined:  2009-03-21
Denmark
 

This is a great post!

If i only want to show these ekstra fields in certain templates, is there someone who will explain which files to copy and place under the theme?

UPDATE:
Found answer here: http://www.magentocommerce.com/boards/viewthread/11110/P0/
Follow Scato’s instructions

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2