Jump to content
stevel

Country-State Selector

Recommended Posts

Dandelion, here's what to do. Replace this code in create_account.php:

<tr>
 <td class="main"><?php echo ENTRY_COUNTRY; ?></td>
 <?php // +Country-State Selector ?>
  <td class="main"><?php echo tep_get_country_list('country',$country,'onChange="return refresh_form(create_account);"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>
 <?php // -Country-State Selector ?>
</tr>

with this:

      <?php echo tep_draw_hidden_field('country', DEFAULT_COUNTRY); ?>

 

You'll need to make a similar change in includes/modules/address_book_details.php

 

KD, I'm still working on your problem.

Share this post


Link to post
Share on other sites
Dandelion, here's what to do.  Replace this code in create_account.php:

<tr>
?<td class="main"><?php echo ENTRY_COUNTRY; ?></td>
?<?php // +Country-State Selector ?>
? <td class="main"><?php echo tep_get_country_list('country',$country,'onChange="return refresh_form(create_account);"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>
?<?php // -Country-State Selector ?>
</tr>

with this:

 ? ? ?<?php echo tep_draw_hidden_field('country', DEFAULT_COUNTRY); ?>

 

You'll need to make a similar change in includes/modules/address_book_details.php

 

KD, I'm still working on your problem.

 

Thanks so very much that's got it!

 

Ruth

Share this post


Link to post
Share on other sites

I'm getting an error in the checkout confirmation for delivery and billing address

 

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/www/html/catalog/includes/functions/general.php on line 42

 

Is this something I did installing this contribution? Do you know how to fix it?

 

Thanks

 

Ruth

 

My Webpage

Share this post


Link to post
Share on other sites

KJ, the change I suggested earlier is bad. As I suspected, it fails to set the zone. Try this instead.

 

Undo the commenting-out I suggested before. Replace this one line:

 

        $zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name like '" . tep_db_input($state) . "%' or zone_code like '%" . tep_db_input($state) . "%')");

with this:

        $zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name = '" . tep_db_input($state) . "')");

 

Let me know how this works for you.

Share this post


Link to post
Share on other sites
I'm getting an error in the checkout confirmation for delivery and billing address

 

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/www/html/catalog/includes/functions/general.php on line 42

 

Is this something I did installing this contribution? Do you know how to fix it?

 

Thanks

 

Ruth

 

My Webpage

I'm trying to get to the bottom of this in the bug fix section http://www.oscommerce.com/community/bugs,1291

 

Thanks so much for helping me get the country province pulldown fixed. FYI I changed the newsletter subscription in this to a radio button so if someone checks it but changes their mind they can unsubscribe again.

 

Do you know how to fix the phone number on this file so that it requires inclusion of the area code - I know it's something to do with the required number of characters but where do I do that.

 

Ruth

Share this post


Link to post
Share on other sites
This topic is for discussion about and support of the Country-State Selector contribution.

 

 

I don't know if this has been addressed before or not, but...

 

I installed (at least partially) your contribution, but since I am using the PWA contribution, I am no longer using create_account.php. I tried using your code in create_account in Order_Info_Check, etc., but so far am unsuccessful. It may be easy if I had a good or even decent knowledge of php.

 

Anyway, just wanted to check if this has been addressed.

Share this post


Link to post
Share on other sites
There was one earlier post but nothing after that.  I have not used PWA myself.

 

Thank for your response. I thought your link would take me to the earlier post, but the link takes me back to your state-selector contribution. Is that what you meant to do?

 

In any event, thanks again.

Share this post


Link to post
Share on other sites

Well, it goes directly to the post for me. Try this one? Not that it will be helpful, except to give you a member name you can perhaps send a PM to to ask if they ever got it working.

Share this post


Link to post
Share on other sites

Hi all.

 

This is a great contribution.. especially when it was working correctly. :'(

 

I have no clue as to what changes I ever made in the past to stop this contribution from working, but here is my prob...

 

The page does not refresh when a different country is selected. I have double, triple, and quadruple checked everything... Made some of the requested changes... nadda.

 

In Firefox, I am getting the javascript console to say "Error: refresh_form is not defined" but when I do a check of the html code in "view source" I see the function for refresh_form.

 

I AM GOING BONKERS AS I HAVE READ EVERY SINGLE LINE IN THE TOPIC AND STILL CANNOT GET THIS TO WORK AS IT USED TO!! ARGGGGHHHHHH!! :angry:

 

Please, for the love of God, can someone (Steve?) take a look at my site and tell me what is wrong? PLEEEEEEEEEEEEASE.

 

By the way, the site is http://shop.snyderhealth.com (click here to go straight to create_account.php)

 

Somewhere it lies in the refresh_form stuff, but it is baffling me at this point... my eyes are bleeding.

 

Thanks to anyone who can help.

 

Again, this is an awesome contribution!

Share this post


Link to post
Share on other sites

Just a quick mention,

 

I am also getting a java console error message of "Error: check_form is not defined".

 

In case that helps with diagnosing this.

 

Thanks again.

Share this post


Link to post
Share on other sites

Well, one thing you appear to have done was add <font color="red" size="1"> to the various ENTRY_xxx_ERROR defines in english.php. The problem with this is that the defines are referenced in includes/form_check_js.php inside strings delimited with "". That makes the embedded " characters give a JavaScript syntax error, and this could have bad effects on the rest of the JavaScript.

 

Try editing the calls to check_input in form_check_js.php to use apostrophe delimiters and see if that helps.

Share this post


Link to post
Share on other sites

First off, great contrib. Thanks.

 

A note on "includes_modules/checkout_new_address.php".

 

Line 80 instructions read:

 

// +Country-State Selector

$zones_array = array();

$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = " . $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 (count($zones_array) > 0) {

echo tep_draw_pull_down_menu('state', $zones_array);

} else {

echo tep_draw_input_field('state');

}

// -Country-State Selector

 

$country should be replaced by (int)$country in the query.

 

Also a note. Because $country has not been set the first time this page is viewed, the state box comes up as a standard text box. Not a big deal. What I did was add this in the line 80 instructions:

 

// +Country-State Selector

// ADDED TO CONTRIB

if(!$country){

$country = DEFAULT_COUNTRY;

}

// ADDED TO CONTRIB

$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']);

}

if (count($zones_array) > 0) {

echo tep_draw_pull_down_menu('state', $zones_array);

} else {

echo tep_draw_input_field('state');

}

// -Country-State Selector

Share this post


Link to post
Share on other sites

Ah, I see. In the readme, I left out the following code that is supposed to be in both checkout_shipping_address.php and checkout_payment_address.php

  // +Country-State Selector 
 if (!isset($country)){$country = DEFAULT_COUNTRY;}
 // -Country-State Selector

Those are the only two files checkout_new_address.php is used from. The code does appear in the pre-edited files I supply. Sorry about that.

 

I'll agree that there really should be an (int) before $country - thanks. I can see a few other improvements I would like to make, and will work on it over the next few days.

Edited by stevel

Share this post


Link to post
Share on other sites

I should not have been so quick to apologize - those changes ARE in the readme....

 

I just uploaded version 1.2 which takes care of the "zone name is substring of another zone name" issue for create_account.php - this was already being done for the other pages. Also some minor bugfixes. See the readme for the change log.

Share this post


Link to post
Share on other sites

Hi Steve.

 

Sorry for my english. I am from Brazil...

 

I made all the changes in the README but I can't see the page create_account.php after the replacements.

 

I made them again but it didn't work anyway. So could you help me?

 

I can send you my create_account.php so you can take look...

 

Thanks a lot.

 

PS: The other changes are working great!

 

--

PC

Edited by pcferreira

PC

Share this post


Link to post
Share on other sites

Forget about it!!!

 

Now it is working fine.... don't ask me why... hehehehe

 

Thank u anyway.

 

--

PC


PC

Share this post


Link to post
Share on other sites
Well, one thing you appear to have done was add <font color="red" size="1"> to the various ENTRY_xxx_ERROR defines in english.php.  The problem with this is that the defines are referenced in includes/form_check_js.php inside strings delimited with "".  That makes the embedded " characters give a JavaScript syntax error, and this could have bad effects on the rest of the JavaScript.

 

Try editing the calls to check_input in form_check_js.php to use apostrophe delimiters and see if that helps.

Thanks Steve brother!!

 

I removed all of the <font color="red" size="1"> from english.php, and now IT WORKS!!! lol

 

Not sure why or when I put those in there, but I don't know why I didn't trace that back.

 

Thanks for opening my eyes a bit.

 

Now I can continue on with my life!

 

Dean

Share this post


Link to post
Share on other sites

Looks like it will be a great addition to my site, however I am having one problem in testing. Since my login and create account are combined into one page it seems to be interfering with the login part of the site. Any ideas as to why and how to fix it?

 

Thanks!


Most Valuable OsCommerce Contributions:

Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294

FedEx Automated Labels -- Contribution 2244

RMA Returns system -- Contribution 1136

Sort Products By Dropdown -- Contribution 4312

Ultimate SEO URLs -- Contribution 2823

Credit Class & Gift Voucher -- Contribution 282

Cross-Sell -- Contribution 5347

Share this post


Link to post
Share on other sites

How many fingers am I holding up? :D This is a joking way of saying "you haven't supplied enough information for me to make any sort of rational guess."

 

The part of C-S Selector that requires care to integrate with other contribs is its addition of the "refresh" action. Study what it does when a refresh is done and make sure that it can also do this on your page. Other contribs may make some assumptions about the actions (for example, assuming that any submission of the form is an attempt to log in or create an account.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×