Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Country-State Selector


stevel

Recommended Posts

Interesting. I wonder why this hasn't come up before. Try this.

 

Change:

    if (count($zones_array) > 0) {
     echo tep_draw_pull_down_menu('zone_id', $zones_array);
   } else {
     echo tep_draw_input_field('state');
   }

to:

    if (count($zones_array) > 0) {
     echo tep_draw_pull_down_menu('zone_id', $zones_array);
     echo "\n" . tep_draw_hidden_field('state','');
   } else {
     echo tep_draw_input_field('state');
   }

Link to comment
Share on other sites

Interesting.  I wonder why this hasn't come up before.  Try this.

 

Change:

 ? ?if (count($zones_array) > 0) {
? ? ?echo tep_draw_pull_down_menu('zone_id', $zones_array);
? ?} else {
? ? ?echo tep_draw_input_field('state');
? ?}

to:

 ? ?if (count($zones_array) > 0) {
? ? ?echo tep_draw_pull_down_menu('zone_id', $zones_array);
? ? ?echo "\n" . tep_draw_hidden_field('state','');
? ?} else {
? ? ?echo tep_draw_input_field('state');
? ?}

 

ok, did that but it says :

 

ERROR: cant move focus to the control because it is invisible, not enabled or of a type that does not accept the focus

 

easiest thing is to disable the IE script thing but that still leaves an unhealthy looking tiny triangle

 

at line 134 all i have is a single bracket ")"

 

anything else that may help please? this is a fresh install - i cant work it out

Upon receiving fixes and advice, too many people don't bother to post updates informing the forum of how it went. Until of course they need help again on other issues and they come running back!

 

Why receive the information you require in good faith for free, only to then have the attitude to ignore the people who gave it to you?

 

There's no harm in saying, 'Thanks, it worked'. On the contrary, it creates a better atmosphere.

 

CHOOCH

Link to comment
Share on other sites

Remove these lines:

<?php // +Country-State Selector
if ($refresh) {echo ' onLoad="document.create_account.state.focus();"';} 
// -Country-State Selector?>

 

Note that the line number refers to the generated HTML, not your PHP.

Link to comment
Share on other sites

Remove these lines:

<?php // +Country-State Selector
if ($refresh) {echo ' onLoad="document.create_account.state.focus();"';} 
// -Country-State Selector?>

 

Note that the line number refers to the generated HTML, not your PHP.

that's it steve - you did it!

 

it's just that the triangle didn't look too good so i wanted to get rid of it

 

cheers mate, you are a top geezer :-)

Upon receiving fixes and advice, too many people don't bother to post updates informing the forum of how it went. Until of course they need help again on other issues and they come running back!

 

Why receive the information you require in good faith for free, only to then have the attitude to ignore the people who gave it to you?

 

There's no harm in saying, 'Thanks, it worked'. On the contrary, it creates a better atmosphere.

 

CHOOCH

Link to comment
Share on other sites

Now to wonder why this didn't cause a problem for others. Might be browser-version-specific, but this is a bug in the code that I will fix.

Link to comment
Share on other sites

Ok, I now understand the problem. All that is needed to fix it is to remove the lines as specified in post 453. I added this from a suggestion earlier, but it doesn't work when the dropdown is there and causes a JavaScript error.

 

I see also that a similar edit appears in address_book_process.php"

 

The following code:

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"
<?php // +Country-State Selector
if ($refresh) {echo ' onLoad="document.addressbook.state.focus();"';} 
// -Country-State Selector?>
>

should be replaced with:

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

 

I'll update the contrib with these changes.

Edited by stevel
Link to comment
Share on other sites

Ok, I now understand the problem.  All that is needed to fix it is to remove the lines as specified in post 453.  I added this from a suggestion earlier, but it doesn't work when the dropdown is there and causes a JavaScript error.

 

I see also that a similar edit appears in address_book_process.php"

 

The following code:

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"
<?php // +Country-State Selector
if ($refresh) {echo ' onLoad="document.addressbook.state.focus();"';} 
// -Country-State Selector?>
>

should be replaced with:

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

 

I'll update the contrib with these changes.

 

thanks for pointing that one out too... i have just changed it.

 

i have another question for you.....

 

is it possible to have a scenario where (in create account) a country is selected (ie. USA) that generates the second dropbox (ie. state=Texas) only for it to then create ANOTHER dropbox with cities (ie. Houston)

 

i have looked at your code and tried to play around with it no matter i do i can't generate the third dropbox - even if i could i would have difficulties trying to get the cities list to be present in the relevant list.

 

the latter is a problem for me to deal with later but can you advise on what i should be aiming for in trying to generate a third dropbox with cities

Upon receiving fixes and advice, too many people don't bother to post updates informing the forum of how it went. Until of course they need help again on other issues and they come running back!

 

Why receive the information you require in good faith for free, only to then have the attitude to ignore the people who gave it to you?

 

There's no harm in saying, 'Thanks, it worked'. On the contrary, it creates a better atmosphere.

 

CHOOCH

Link to comment
Share on other sites

...and causes a JavaScript error....

 

I see also that a similar edit appears in address_book_process.php"

 

I'll update the contrib with these changes...

this is interesting. I was curious about this. I have my browser set up to not debug.

i went ahead and changed the setting. (IE by the way)

 

I had your code implemented that supossedly throws these errors. I never got those errors.

What intrigues me: I did get some errors.

I have my address book set up to hold three addresses.

The account I was testing (testing my paypal webpayments pro mods) has three addresses in it. when I get to the checkout_shipping page I tried to change my shipping address. I checked the one that holds my fake paypal test card and on "continue" to update the address I got this:

 

A RUNTIME ERROR HAS OCCURRED

do you wish to debug?

line:48

error: 'elements.firstname.value' is null or not an object

 

if I delete one address so it is not full, the error stops. add one to fill it. error.

this happens on the payment part too, if i try to change the billing address when the book if full.

 

i have also edited all the country/state selector code as per the fix in post #453 (using that as a guideline for any other country/state pages that had it).

 

this does not happen when the address book is not full. the only difference between the page when I try to change the address, when book full or not is when its full, the place to add a new address isn't loaded. when i have room to add more we get the "address lines" to load.

 

Looks like I need to go runtime bug hunting. I believe my errors have nothing to do with contribution, but it is here that I discovered it.

Link to comment
Share on other sites

Aleem,

 

The way I recommend you handle this is to add zones for the individual cities you care about, such as Texas - Houston, Texas - Dallas, etc. Then you'd rename the Texas zone to be "Texas - Other". You'd do this if you needed to add taxes for specific cities. This does depend on the customer entering the correct zone.

 

Ideally, one would have a Zip code lookup to make the decision for the customer, but getting the data for that is tricky.

 

Michael, debugging this sort of thing is pretty easy. Just do a View Source of the page in the browser. In your case, you will probably find that the "elements" form either does not exist or has no "firstname" field. I'm not a JavaScript expert, but I imagine there is some way to test whether a name exists before referencing it.

Link to comment
Share on other sites

Aleem,

 

The way I recommend you handle this is to add zones for the individual cities you care about, such as Texas - Houston, Texas - Dallas, etc.  Then you'd rename the Texas zone to be "Texas - Other".  You'd do this if you needed to add taxes for specific cities.  This does depend on the customer entering the correct zone.

 

Ideally, one would have a Zip code lookup to make the decision for the customer, but getting the data for that is tricky.

Steve

 

thanks for the reply...

 

i will look in to this when i have time to pay it proper attention. even then it'll take me ages to figure it out properly but this will be a very good add-on for a project of mine.

 

thanks again for your support :-)

Upon receiving fixes and advice, too many people don't bother to post updates informing the forum of how it went. Until of course they need help again on other issues and they come running back!

 

Why receive the information you require in good faith for free, only to then have the attitude to ignore the people who gave it to you?

 

There's no harm in saying, 'Thanks, it worked'. On the contrary, it creates a better atmosphere.

 

CHOOCH

Link to comment
Share on other sites

Hello ! I am trying to change the way the contribution define the country of a customer. The idea is insert name of the country and even city by IP address .

Now i am look at WHO'S ONLINE or USER TRACKING way.

 

I thought maybe somebody will so kind and help me with the coding , unfortunately

i do not know PHP so i am stacked.

thank you

Link to comment
Share on other sites

Sorry, but the IP address isn't accurate enough for this. For example, my IP address shows up as a city about 30 miles away in another state.

 

Don't try to be too clever when asking customers for their address. They know it better than you do.

Link to comment
Share on other sites

Michael, debugging this sort of thing is pretty easy. Just do a View Source of the page in the browser. In your case, you will probably find that the "elements" form either does not exist or has no "firstname" field. I'm not a JavaScript expert, but I imagine there is some way to test whether a name exists before referencing it.

Yuppers Steve. Thanks for the nudge. Here's my solution for anyone that finds this thread for a problem that does not belong in this topic!!!

 

If your address book is full and you get a runtime error when you try to change the shipping address or the payment address this code needs to be changed in both these files:

 

checkout_shipping_address.php

checkout_payment_address.php

 

find:

function check_form_optional(form_name) {
 var form = form_name;

 var firstname = form.elements['firstname'].value;
 var lastname = form.elements['lastname'].value;
 var street_address = form.elements['street_address'].value;

 if (firstname == '' && lastname == '' && street_address == '') {
   return true;
 } else {
   return check_form(form_name);
 }
}

and replace that with

function check_form_optional(form_name) {
 var form = form_name;
 //runtime error fix when book full
 if (!form.elements['firstname']) {
 return true;
 } else {
 //end error fix
 var firstname = form.elements['firstname'].value;
 var lastname = form.elements['lastname'].value;
 var street_address = form.elements['street_address'].value;

 if (firstname == '' && lastname == '' && street_address == '') {
   return true;
 } else {
   return check_form(form_name);
 }
}
//next bracket is needed for runtime error fix
}

this stops the script from trying to find an element that does not exist.

Link to comment
Share on other sites

Hi Steve.

 

Thanks for a great contribution!

 

 

Can you or anyone else please try a test with the PWA mod in place?

 

Specifically, select an item to purchase, go through the PWA option (enter a new email account etc.) then abandon the purchase when you get to the payment page.

 

Close your browser.

Launch a new browser then go back and try to buy something else through PWA - try to enter the email account details that you used earlier.

 

Do you get an error message saying that the email account already exists?

Normally PWA would delete this hung-over PWA account but I don't think it is doing that in the CSS version.

 

Of course there could be a problem with other contributions I'm using - so I am asking for other peoples experience with CSS/PWA here.

Link to comment
Share on other sites

Yes, I see that behavior too. I'll see if I can figure it out when I get the chance. I just copied the processing code from PWA, so I don't understand what would be different. But I could have made an error here.

Link to comment
Share on other sites

Found it. Remove these lines from Order_Info.php (around line 103)

  } else {
   $check_email_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
   $check_email = tep_db_fetch_array($check_email_query);
   if ($check_email['total'] > 0) {
	 $error = true;

	 $messageStack->add('create_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
   }

Link to comment
Share on other sites

Oh, and at around line 550, the line after:

   <?php echo tep_draw_hidden_field("password","DummyForPWA") . tep_draw_hidden_field("confirmation","DummyForPWA"); ?>

delete the </tr> - it doesn't belong there.

Link to comment
Share on other sites

Found it.  Remove these lines from Order_Info.php (around line 103)

 ?} else {
? ?$check_email_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
? ?$check_email = tep_db_fetch_array($check_email_query);
? ?if ($check_email['total'] > 0) {
?	$error = true;

?	$messageStack->add('create_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
? ?}

 

Steve, I can't test this out for a while so please excuse me asking this...

 

If you do this modification then try to use PWA with a genuine fully registered email address - does PWA still recognise that and give a genuine error for that?

In this case the customer should be redirected by the error to use the existing account.

Link to comment
Share on other sites

I believe so, yes. This is a different part of the code. It was code I copied from create_account but shouldn't have.

 

I'll hold off updating the contrib for a day or two while people try this out.

Link to comment
Share on other sites

i am using this bit from pwa contribution in mine but i have changed the table column so i might be wrong in the column name noaccount but you should find out soon enough

you have to change

if ($check_email['total'] > 0) {
       $error = true;

       $messageStack->add('create_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
     }

to

if ($check_email['total'] > 0)
{  //PWA delete account
  	 $get_customer_info = tep_db_query("select customers_id, customers_email_address, noaccount from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
 $customer_info = tep_db_fetch_array($get_customer_info);
 $customer_id = $customer_info['customers_id'];
 $customer_email_address = $customer_info['customers_email_address'];
 $customer_pwa = $customer_info['noaccount'];
 if ($customer_pwa =='Y')
 {
       $error = true;
       $messageStack->add('create_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
 } else {
	 tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $customer_id . "'");
	 tep_db_query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");
	 tep_db_query("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customer_id . "'");
	 tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . $customer_id . "'");
	 tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . $customer_id . "'");
	 tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where customer_id = '" . $customer_id . "'");
 }
     }
// END

Link to comment
Share on other sites

Steve-

 

Thank you for this contrib- it was something that absolutely needed to be done for my site!

 

Btw, is it possible to change the order that the zip code, city, and state input fields are displayed in? Currently it's zip code, city, state, but I would like it to be city, state, zip code. It seems like it should be easy but it's got me stumped.

 

Cheers

Stew

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

Oh-

 

Since installing this mod, I'm getting this when attempting to view admin/customers.php:

 

Parse error: parse error, unexpected T_CASE in /var/www/html/admin/customers.php on line 220

 

Here are lines 219-221:

 

break;
     case 'deleteconfirm':
       $customers_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

First, it's easy to change the order of the fields. Simply move this code:

              <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>

to just before these lines:

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

 

The other problem is likely caused by some edit prior to the code you show. A missing quote is most common.

 

Did you use the file I supplied or did you do the edits yourself?

Link to comment
Share on other sites

I did the edits myself as my store is heavily modified already, and I'm finding a lot of errors. I did a lot of cut and paste using a couple different text editors and a lot of html symbols ended up appearing in places they shouldn't.

 

In what file would I find the code to change to order of the fields, or is it in many files?

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

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...