Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add DROPDOWN BOX for STATES --- I know What you want :)


Dallas1906

Recommended Posts

This is my first time adding something but I know a lot of people from the states needed a dropdown list for the Create Account page ( i did too), so I added one in, its very simple so listen up

 

step 1: go to the file catalog/includes/modules/account_details.php

 

step 2: find the portion of code that is dealing with states you should see something like this

 

 

if (ACCOUNT_STATE == 'true') {

 

Thats the beginning of the portion of code. dont touch that though

 

step 3: go to the last else of that php block and remove its contents

I think it starts with echo tep_draw_input_field

 

step 4: replace with:

 

$zones_array = array();

         $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $account['entry_country_id'] . "' 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) . ' ' . ENTRY_STATE_TEXT;

 

step 5: save your code and it should bring up a drop down list (dont forget to check that all your code end with correct semi-colons and brackets are closed correctly)

 

HAVE A NICE LIFE :lol:

--- There are two kinds of people in this world those who are taking care of Business and those who are not, which one are you?

Link to comment
Share on other sites

Here is a correction for the pull down menu.

 

echo tep_draw_pull_down_menu('state', zones_array,tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account 'entry_state']))  . ' ' . ENTRY_STATE_TEXT;

Link to comment
Share on other sites

hobaugh, I tried this.

 

I am getting parse error line 282 which is the new (correction) for the pulldown.

 

I inserted the old pulldown code and it seems to work. I have a 01-06-2003 snapshot.

 

What is the difference in the two?

 

-Al

Link to comment
Share on other sites

This is the only difference.

 

tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])

 

The old code does not have the state selected if the user goes to edit the account. This code tells the fuction that this state should be selected.

 

Doug

[/url]

Link to comment
Share on other sites

Sorry I was not clear.

I see that in the code but when I use it I get the parse error on line 282. When I do not use it everything seems fine.

 

Any thoughts.

 

-Al

Link to comment
Share on other sites

Here is all of the code. Maybe I missed something before.

I don't get an error. I'm using the snapshot from around 2002/11/23.

 

$zones_array = array(); 

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $account['entry_country_id'] . "' 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,tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

Link to comment
Share on other sites

Sorry I was not clear.

I see that in the code but when I use it I get the parse error on line 282. When I do not use it everything seems fine.

 

Any thoughts.

 

-Al

Link to comment
Share on other sites

  • 2 weeks later...

For address_book_details.php, change $account to $entry.

 

$zones_array = array();

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $entry['entry_country_id'] . "' 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,tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

Link to comment
Share on other sites

  • 3 weeks later...

thanks guys i was looking for this code;

 

$zones_array = array(); 

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $account['entry_country_id'] . "' 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,tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

 

Life savers!

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Link to comment
Share on other sites

The dropdown box is nice.

 

But, it doesn't automatically refresh when the country is changed, and no input is allowed for the new country. I see the current demo at the oscommerce.com site. These problems are solved. States are autometically updated when the country is changed. And there is an input box for entering a state name when zone list is not available.

 

Did I miss anything? or there is an update? where can I get the update?

 

Thanks

 

David

David

We support osCommerce

Link to comment
Share on other sites

  • 1 month later...

The State drop down works great for me...I have removed country. The only problem is when you click continue after putting in all the information it highlights that field as required. Also it doesn't matter what you then type in for state, it won't register, and continues to say required. Anyone have an idea for this?? Thanks!!!

 

-Richard

 

www.gobeyondwireless.com/catalog/create_account.php

-Richard

---------------------------------------------------

Where would I be without the Forums?!?!

Link to comment
Share on other sites

  • 4 weeks later...

How can this:

 

$zones_array = array(); 

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $account['entry_country_id'] . "' 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,tep_get_zone_name($account['entry_country_id'], $account['entry_zone_id'], $account['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

 

work in checkout_new_address.php?

Link to comment
Share on other sites

  • 2 weeks later...

Having the same problem here.. Has anyone figured out how to automatically update the State/Province dropdown box when Country changes from United States to Canada? Thanks muchly!

Link to comment
Share on other sites

In order to update the state/province list based upon the country selected would require javascript. Since a good majority of users surfing the web have JS disabled, the solution would fail anyway.

 

The only way around that would be a 2-step process - the user selects their country and clicks ok. Then on the next page the list of states/provinces is provided based upon the country entry made on the previous page. Needless to say, this would be a total pain in the arse.

 

Unless you set your front page so that the user selects their country at the beginning but then you would have to create the session early and then carry that information. Not very feasible, especially for robots.

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

Hey Jim,

Thanks for the reply. I agree that enough people disable javascript and I didnt want to use JS for this.

 

With that said, I have deleted all countries from the database except for both the US and Canada. I'd like to somehow combine the 2 countries to share the same 'zone_country_id'. Since the US uses 223 and Canada uses 38 I was wondering if I could simply edit all the Canada entries and change them to 223. This would allow people to select both the State/Province as well as the Country from a dropdown box.

 

My question is.. Does anyone know if this change would screw anything else up?

 

Many thanks!

Link to comment
Share on other sites

Incorporating Canada into the US would throw your shipping rate estimates out the window. :(

"Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein

Link to comment
Share on other sites

  • 1 month later...
For address_book_details.php, change $account to $entry.

 

$zones_array = array();

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $entry['entry_country_id'] . "' 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,tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state'])) . ' ' . ENTRY_STATE_TEXT;

 

How can I use this for 'checkout_new_address.php'? I have tried changing $account to $entry and all I get is an empty drop down box. Is there a simple change? All the other code works great! Thanks.

Link to comment
Share on other sites

  • 3 weeks later...
How can I use this for 'checkout_new_address.php'?  I have tried changing $account to $entry and all I get is an empty drop down box.  Is there a simple change?  All the other code works great!  Thanks.

 

I'm having the same problem here. Does anyone have a fix for checkout_new_address.php?

 

Thanks a lot!

 

- Mike

Link to comment
Share on other sites

How can I use this for 'checkout_new_address.php'? I have tried changing $account to $entry and all I get is an empty drop down box. Is there a simple change? All the other code works great! Thanks.

 

I'm having the same problem here. Does anyone have a fix for checkout_new_address.php?

 

Thanks a lot!

 

- Mike

 

I did this:

 

<?php

if ($process == true) {

$state = tep_get_zone_name($country, $zone_id, $state);

if ($entry_state_error == 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 = '" . tep_db_input($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) . ' ' . ENTRY_STATE_ERROR;

} else {

echo tep_draw_input_field('state') . ' ' . ENTRY_STATE_ERROR;

}

} else {

echo $state . tep_draw_hidden_field('zone_id') . tep_draw_hidden_field('state');

}

} else {

$zones_array = array();

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . STORE_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) . ' ' . ENTRY_STATE_TEXT;

// echo tep_draw_input_field('state') . ' ' . ENTRY_STATE_TEXT;

}

?>

 

A quick kludge, but we're only going to be selling domestic USA for now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...