Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to get state pulldown list


stevel

Recommended Posts

I have searched this forum as many ways as I can think of, and haven't been able to find the answer to a question that I'd think was common.

 

I have 2.2-MS2, almost entirely stock (at the moment.) In the places where a customer's address is asked for, such as create_account.php, I get just a standard text entry field for State rather than a pulldown list for the states in the country zone (US in this case).

 

I see that this page looks for variables such as ACCOUNT_STATE, but these are not defined anywhere I can find. There is a configuration item for what looks to be this value in admin, and I have it set to true, but this makes no difference, nor does adding an explicit definition in application_top.php.

 

The code here clearly is looking to see if the zone has states, but I don't understand enough about PHP nor MySQL to figure out why it doesn't want to build the pulldown. The Zones configuration properly shows the zones for the US.

 

In the admin panel, My Store, Country is set to United States and Zone is set to New Hampshire. But I'd think that customers would be able to select their own country and then state. I wouldn't mind if it assumed US (since for my store, I won't be accepting non-US orders), but I need to understand how this is supposed to work and get the pulldown there.

 

What have I missed? Thanks for any help you can provde.

 

Steve

Link to comment
Share on other sites

It doesn't know that it's the US until you select the country, so it doesn't know that it should be selecting a state yet (it could need a province, county, or nothing). The following code is a diff from two versions of create_account.php. The first one has the default behavior (lines beginning with <); the second displays all states (US) and provinces (Canadian) for a store that delivers to both (lines beginning with >). Presumably, dropping the "or zone_country_id = 38" would make it only show US states. Note: the line numbers will probably not match those in your file, as this version is heavily modified in other ways as well.

437,438c437,438
<     if ($process == true) {
<       if ($entry_state_has_zones == true) {
---
> //    if ($process == true) {
> //      if ($entry_state_has_zones == true) {
440c440,441
<         $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
---
>         $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 223 or zone_country_id = 38 order by zone_country_id DESC, zone_name");
>               //'" . (int)$country . "' order by zone_name");
445c446
<       } else {
---
> /*      } else {
448c449
<     } else {
---
> /*    } else {
450c451
<     }
---
>     }*/

Hth,

Matt

Link to comment
Share on other sites

  • 1 month later...

Matt,

 

Your state pulldown list works great in osC 2.2 MS2

 

catalog/create_account.php

 

and in

 

catalog/includes/modules/Order_Info_Check.php used by the Purchase Without Account contribution.

 

Thanks a lot! :D

EricK

Link to comment
Share on other sites

  • 2 weeks later...

Backup first (in case you need to undo this). Then delete the countries that you don't want. There is an admin interface for this in MS2 that I think was in MS1.

 

Hth,

Matt

Link to comment
Share on other sites

Matt,

 

I join Erik in thanking you for your assistance. The code changes for the create_account.php file work flawlessly. By any chance have you also added a states pull down selection for the checkout_shipping_address.php & address_book_process.php files? The code in each of these two are almost identical, but different enough from the create_account.php script to be a bit confusing to someone just beginning to climb the learning hill (or mountain).

 

Steve

Link to comment
Share on other sites

Matt,

 

I must be missing something because your mod suggestion only worked partially for me.

 

I've reviewed your code and I just don't understand something. You suggest the following...

> /*      } else {
448c449
<     } else {
---
> /*    } else {
450c451
<     }
---
>     }*/

 

What I don't understand is that there are TWO "/*" and only ONE "*/". It seems that one of those "/*" never gets closed appropriately.

 

After making the changes you suggest the new user registration screens work great (I get the drop-down list of states). The new user gets added to the database. The problem that I encounter is when I attempt to log. I enter the email address and password, and even though the user is in the database, after selecting "Sign In" I get bounced back (taken back) to the same Sign In screen. I never get logged in.

 

Am I correct in assuming that the unclosed "/*" might be causing the problem?

 

-jp

Link to comment
Share on other sites

I doubt it, but you could leave off the second one and see if it helps. I don't really remember why things were commented out in that section...one of them might have been redundant. It's also possible that it relied on the comments treating /* /* */ the same as /* */, i.e. /* in comments are ignored usually (that's configurable in C, not sure about PHP). I could give a better guess with a copy of the modified code from 445 to 451.

 

If you use the forgotten password module, can you log in with the password you get then? If that password does not work, then I would think that the problem lies in the login.php page somewhere. Have you made any other mods recently?

 

Hth,

Matt

Link to comment
Share on other sites

Not surprisingly I got a little lost yet again. The additional files which I needed to change were in fact catalog/includes/modules/checkout_new_address.php and

catalog/includes/modules/address_book_details.php

 

I ended up mixing together parts from posts made by Matt aka iiinetworks and

Jason aka webguy. Credit goes solely to them. Thanks.

 

If anyone is interesested here are the changes I made to add a states pull down selection for the Update Address Book Entry, New Address Book Entry, & Delivery Information pages. (I suspect that there is a more elegant way to pull this off, but this seems to work.)

 

In catalog/includes/modules/checkout_new_address.php I replaced:

<?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");
       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);
     } else {
       echo tep_draw_input_field('state');
     }
   } else {
     echo tep_draw_input_field('state');
   }

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

 

with:

<?php
   //    if ($process == true) {
     //      if ($entry_state_has_zones == true) {
       $zones_array[] = array('id' => '', 'text' => 'Please Select');
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 223 or zone_country_id = 38 order by zone_country_id DESC, zone_name");
       //'" . (int)$country . "' 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, 'Please Select');
     /*      } else {
       echo tep_draw_input_field('state');
     }
   /*    } else {
     echo tep_draw_input_field('state');
   }*/

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

 

And in catalog/includes/modules/address_book_details.php I replaced:

<?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");
       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);
     } else {
       echo tep_draw_input_field('state');
     }
   } else {
     echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
   }

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

 

with:

<?php
   //    if ($process == true) {
     //      if ($entry_state_has_zones == true) {
       $zones_array[] = array('id' => '', 'text' => 'Please Select');
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 223 or zone_country_id = 38 order by zone_country_id DESC, zone_name");
       //'" . (int)$country . "' 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']);
       }
     if (tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']) == "") {
echo tep_draw_pull_down_menu('state', $zones_array, 'Please Select');
} else {
     echo tep_draw_pull_down_menu('state', $zones_array, tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
}

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

 

Hope this helps someone.

Link to comment
Share on other sites

Matt, I have to extend my apologies. Although I haven't taken time to go back and evaluate your code revisions it seems that something else is causing the issue that I described earlier...

after selecting "Sign In" I get bounced back (taken back) to the same Sign In screen. I never get logged in.

I've been noticing some problems that are specifically related to accessing my osCommerce site via MSIE. It seems to be a caching issue, but I'm not quite certain. I had returned the login file back to "normal" after encountering the problem that I described earlier. When I tried to log in with MSIE v5.50 I encountered the same, quirky problem described earlier. However, on the exact same PC, when using Mozilla 1.5, the problem was non-existent. I was able to log in normally. On another PC with MSIE 6.0 the login worked fine too.

 

Sure wish I had a handle on this. Kinda bad having to tell my clients... you must use Mozilla or a recent version of MSIE in order to assure a quality shopping experience.

 

Hey, thanks for the mod! I'll re-install it and will report back to the Forum.

Link to comment
Share on other sites

  • 3 months later...

Great contrib, I'm installing it as we speak.

 

1 thing, the install instructs aren't copy/paste friendly in the way they are written. If its just me or my machine, let me know. But I've had to copy/paste and manually add my line feeds.

 

Great contrib though, I'll let you know if I have any problems with it...

9 times out of 10 its a PEBCAK Error (Problem exists between chair and keyboard)

 

Replace that and you're fine...

Link to comment
Share on other sites

Theres an error in this contrib. When you go into account info then into your address book then hit edit on one of your address book entries you get an

Parse error: parse error, unexpected '}' in /www/f/fmabdulky/htdocs/catalog/address_book_process.php on line 205

I then tried taking out the } and then whenever you edit or delete an address book entry, it creates a new entry with a " , " as the only entry.

If I was crafty, this would be a funny signature.

Link to comment
Share on other sites

I know about the install instructs issue - discovered that minutes after I posted! I will fix that today., though as an alternative you can copy the code out of the supplied files.

 

ryanf, I don't get that on my site, which I edited following the install instructions. What do you have between lines 195 and 210?

 

I suggest moving discussion of this contribution to http://www.oscommerce.com/forums/index.php?showtopic=88987

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...