Jump to content

Archived

This topic is now archived and is closed to further replies.

gogowanda

US state dropdown list in customer account creation

Recommended Posts

hi all,

i searched but nothing related showed up

a few of my customers brought this to my attention. they were not asked to enter state while creating an account. so i enabled state view from the database but it then just a plain text field. i wonder if i can set my country to united states then populate a state dropdown list.

i also searched contribution list but found nothing. so if anyone can give me some advices i'd greatly appreciate it!

 

thanks

Share this post


Link to post
Share on other sites

If you only have the one country, you could do your state pulldown like this in create_account.php (MS2) - its just an edited version of what is already there:

 

<?php

 if (ACCOUNT_STATE == 'true') {

?>

             <tr>

               <td class="main"><?php echo ENTRY_STATE; ?></td>

               <td class="main">

<?php

       $zones_array[] = array('id' => '', 'text' => 'Please Select');

       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '223' order by zone_name");

       while ($zones_values = tep_db_fetch_array($zones_query)) {

         $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);

       }

       echo tep_draw_pull_down_menu('state', $zones_array);

       

   if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;

?>

               </td>

             </tr>

<?php

 }

?>

 

NOTE: The zone_country_id (db zones table) in the above example is for the USA - the appropriate id for your country must be entered into the code.


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

Johnson,

 

Is it possible to post the code for this to work with MS1?

 

 

 

Thanks!!

 

Mark

Share this post


Link to post
Share on other sites
Johnson,

 

Is it possible to post the code for this to work with MS1?

 

Did you try it? - I just had a quick look at catalog/includes/modules/account_details.php (yes, a different file) and it should work ok, the variables are the same - like I said, I have not tested it at all :shock:

 

I have edited the above post so it is easier to see how it slots into the code


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

I am not sure I understand the array completely. There are no states in the drop down box.

 

 

Mark

Share this post


Link to post
Share on other sites

Just tested and have updated above to actually work! :shock:

 

You must enter your zone_country_id from the zones table for it to work

 

We still have to deal with countries - if we only have one, then we do not need it in account signup. We could make it default to our chosen country in the database, but it must still be dealt with appropriately in the create account process.... :?


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

Johnson,

 

 

It works! One SMALL problem though. You left off the ">" at the very end of the above code. Other than that, it is a winner!!

Thanks!!

 

 

Mark

Share this post


Link to post
Share on other sites

hi johnson, it worked! thanks!

but i got a couple of canadians in my email box complaining :P

is it possible to modify the country dropdown list to make US and Canada to appear on top two items?

or even better, to generate state dropdown list if US is selected. well i know i'm asking too much. if you could point me out the direction i'll see if i can put up a contribution.

 

thank you so much!

Share this post


Link to post
Share on other sites
hi johnson, it worked! thanks!

but i got a couple of canadians in my email box complaining :P

is it possible to modify the country dropdown list to make US and Canada to appear on top two items?

or even better, to generate state dropdown list if US is selected. well i know i'm asking too much. if you could point me out the direction i'll see if i can put up a contribution.

 

thank you so much!

 

Well - if you read above you will see that I said it was for a single country - just a quick hack :shock:

 

What you want could be done with 'onclick' - I have thought of this myself several times - ie. selecting their country as the link to the signup process - this would require the countries drop menu before the signup page, as a refresh while filling in a form is too startling to most customers.


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

I get a parse error at life 443. if (ACCOUNT_STATE == 'true') {

 

I'm obviously missing something. :cry:


Roadracing makes heroin addiction look like a vague wish for something salty.

Share this post


Link to post
Share on other sites

Yes - you have a typo - check it again - I just copy and pasted what I posted here and there wasn't a problem. What is the exact error message?


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

johnson, thx, i'm a half-ass self-taught programmer i'll try to give it a shot. :roll:

 

well for now could you tell me how to change the list order for countries? since most of my customers are from US and Canada, i want to list these two countries on top of the list. or just make US a default. i tried it in the db table but didn't work (i put default country value to "unitied states").

Share this post


Link to post
Share on other sites

Thanks Mr. Johnson,

 

Parse error: parse error in /www/catalog/create_account.php on line 443

 

Is the exact error and here's the code and a couple of lines on either side.

 

 <tr>

               <td class="main"><?php echo ENTRY_CITY; ?></td>

               <td class="main"><?php echo tep_draw_input_field('city') . ' ' . (tep_not_null(ENTRY_CITY_TEXT) ? '<span class="inputRequirement">' . ENTRY_CITY_TEXT . '</span>': ''); ?></td>

             </tr>

             

             

<?php 

? if (ACCOUNT_STATE == 'true') { 

?> 

? ? ? ? ? ? ? <tr> 

? ? ? ? ? ? ? ? <td class="main"><?php echo ENTRY_STATE; ?></td> 

? ? ? ? ? ? ? ? <td class="main"> 

<?php 

? ? ? ? $zones_array[] = array('id' => '', 'text' => 'Please Select'); 

? ? ? ? $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '223' order by zone_name"); 

? ? ? ? while ($zones_values = tep_db_fetch_array($zones_query)) { 

? ? ? ? ? $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']); 

? ? ? ? } 

? ? ? ? echo tep_draw_pull_down_menu('state', $zones_array); 

? ? ? ? 

? ? if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT; 

?> 

? ? ? ? ? ? ? ? </td> 

? ? ? ? ? ? ? </tr> 

<?php 

? } 

?> 





             <tr>

               <td class="main"><?php echo ENTRY_POST_CODE; ?></td>

               <td class="main"><?php echo tep_draw_input_field('postcode') . ' ' . (tep_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="inputRequirement">' . ENTRY_POST_CODE_TEXT . '</span>': ''); ?></td>

             </tr>


Roadracing makes heroin addiction look like a vague wish for something salty.

Share this post


Link to post
Share on other sites
Thanks Mr. Johnson,

 

Parse error:  parse error in /www/catalog/create_account.php on line 443

 

Aha! You'd think I'd know to check this sort of thing before I announced to the world that I'm daffy.

 

There was a non-ASCII character in there. There's a something for everyone to remember. I obviously need to follow my own advice!


Roadracing makes heroin addiction look like a vague wish for something salty.

Share this post


Link to post
Share on other sites

I guess I did something wrong:

after I submit form I get this error message/.

 

You must select a country from the Countries pull down menu.

how do I make USA as the default country ?

Share this post


Link to post
Share on other sites

OK i think I found the problem with the error.

 

the only thing I would like to know how to chage the country as ready made text USA and no drop down or text box.

Share this post


Link to post
Share on other sites

Is there a way to add multiple zones to the drop down list?

 

For Canada and US... -- zones 38 and 223 ?

 

I wouldn't want to duplicate the Canadian Zones as Duplicate US

Zones as that would lead to problems.

Share this post


Link to post
Share on other sites
Is there a way to add multiple zones to the drop down list?

 

For Canada and US... -- zones 38 and 223 ?

 

I wouldn't want to duplicate the Canadian Zones as Duplicate US

Zones as that would lead to problems.

 

There is - however, there are other things that also need to be dealt with to do that which, on the surface, appears simple.

 

As I said in my previous post, the best way is to have the customer select their country *on their way* to the create account process - as you say, mixing zones is not a solution.

 

I will begin work on a contribution..... hmmm... all this to save a few keystrokes for our customers :shock:


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites
Johnson

 

Just wondering if you have released a contribution for this yet.

 

No - I am a very busy man - I shall post to this thread and also in the Contributions channel when I do... it is in progress :shock:


Matti Ressler

 

We were all once expert at...... nothing

_____

Share this post


Link to post
Share on other sites

Hi

This mod is just what I wanted but am also getting parse error in /catalog/create_account.php on line 453

I have copied Johnsons code exactly from page 1 of this thread and just changed the country code, here it is and a few lines either side:

 

<td class="main"><?php echo ENTRY_CITY; ?></td>

<td class="main"><?php echo tep_draw_input_field('city') . ' ' . (tep_not_null(ENTRY_CITY_TEXT) ? '<span class="inputRequirement">' . ENTRY_CITY_TEXT . '</span>': ''); ?></td>

</tr>

<?php

if (ACCOUNT_STATE == 'true') {

?>

<tr>

<td class="main"><?php echo ENTRY_STATE; ?></td>

<td class="main">

<?php

$zones_array[] = array('id' => '', 'text' => 'Please Select');

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '222' order by zone_name");

while ($zones_values = tep_db_fetch_array($zones_query)) {

$zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);

}

echo tep_draw_pull_down_menu('state', $zones_array);

 

if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;

?>

</td>

</tr>

<?php

}

?>

<?php

if ($process == true) {

if ($entry_state_has_zones == true) {

$zones_array = array();

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");

 

Any help would be greatly appreciated.


thanks

Rich

"May the seam be with you"

Share this post


Link to post
Share on other sites

Hi

One more question, when someone now wishes to change the state he lives in (maybe he selected the wrong one from the pull-down, these things do happen) any clues on what needs to be changed in /catalog/address_book_process.php ?

Thanks


thanks

Rich

"May the seam be with you"

Share this post


Link to post
Share on other sites

Hi

Sorry to be a pain but has anyone any ideas about the above post?


thanks

Rich

"May the seam be with you"

Share this post


Link to post
Share on other sites

×