Jump to content
stevel

Country-State Selector

Recommended Posts

Also, When I go to address_book_process.php I get the following at the top of the page .... (like it was typed as text)

 

onLoad="document.addressbook.state.focus();"

 

I am sure I can figure it out but this kinda has to do with my last post about where to put things with the BTS system.

 

Let me know your thoughts.

 

Craig

Share this post


Link to post
Share on other sites

Ok, in address_book_process.tpl.php I had the following at the top:

 

<?php // +Country-State Selector

if ($refresh) {echo ' onLoad="document.addressbook.state.focus();"';}

// -Country-State Selector?>

 

Of course it wasn't working because the ?> was in a commented line but the point is that it still works. I am guessing because I added this same line to the mainpage.tpl.php file too so it is included in ALL files. Am I right?

 

If so what about what I said before about installing other contribs?

 

Thanks!!

 

Craig

Share this post


Link to post
Share on other sites

First - I do not recommend you try converting zip code to city and state. A single zip code may be used for more than one town, if one post office handles mail for residents of the other towns. I used to live in a town such as that and the companies that did try to translate the zip code and ignore what I typed in were always causing me trouble.

 

The way you use this for template contributions is to take the code that processes the form and add it to the template driver file. The part that has HTML (with embedded PHP) that is the form goes in your template. I set this up for someone once, and it took me maybe half an hour. If you think about how the template contributions work, it isn't that hard.

 

The code you show in your last post works fine normally - I'm guessing the template reader gets confused by it though. Note that this particular part is added to the <body> tag of the page.

Share this post


Link to post
Share on other sites

I dont understand what you are saying. I did add the code to the template files and it does work but what I am asking is since I added the <body> code (that would normally have went in the seperate files) into the main_page.tpl.php file (which is processed on EVERY page) how does that work with OTHER contribs that need to modify the body tag?

 

I would assume that they could all coexist together in the body tags but I would rather not assume anything. Also, Is that healthy to have several phh snippets ran on ALL pages? Since the code went into the main template file and not the individual pages it is now ran on every page on the site. Let me know know what you think.

 

About the zip codes, our inventory management software (not web based) has this feature (and so does UPS WorldShip Software) and neither of them are wrong more than 1% of the time. Even when they are I am still allowed to change the city name, it is just nice that it enters what it thinks it is for me. Also, if the address is entered first you COULD have the script check for zip+4 with usps.com, that is accurate with no mistakes. I am sure that is overboard but possible. I would just like to be able to have the customer enter name, then street address, then zip (then it populates city and state) and they can make corrections if anything it incorrect.

 

What do you think?

 

Craig

Share this post


Link to post
Share on other sites

hi,

 

i am little bit of confused - installed the contrib today and it works fine - just at the address_book_process.php page when changing to anohter country with provinces there is this enoying javascript error saying: can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. - error is at line 144.

 

somewhere here

 

if ($error == false) {

 

$sql_data_array = array('entry_firstname' => $firstname,

'entry_lastname' => $lastname,

'entry_street_address' => $street_address,

'entry_postcode' => $postcode,

'entry_city' => $city,

'entry_country_id' => (int)$country);

 

if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;

if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;

if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;

if (ACCOUNT_STATE == 'true') {

if ($zone_id > 0) {

$sql_data_array['entry_zone_id'] = (int)$zone_id;

$sql_data_array['entry_state'] = '';

} else {

$sql_data_array['entry_zone_id'] = '0';

$sql_data_array['entry_state'] = $state;

}

}

 

 

THE STRANGE THING ABOUT THAT - in firefox 1.0 no error is detected by the javascript console.

 

error doesnt jump up when chaning to a country without provinces

 

ANYBODY HAS AN IDEA?

 

the contribution is really great !!!!

 

thanx for any help

 

martin

Share this post


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

:blink: I just had a customer email me that there is no FL in the state drop down of the customer information page. Does anyone know where the state array/database is stored so I can replace Florida?

Share this post


Link to post
Share on other sites
:blink:  I just had a customer email me that there is no FL in the state drop down of the customer information page. Does anyone know where the state array/database is stored so I can replace Florida?

 

In your admin/loactions/zones. Make sure it is not there before adding it again. : )

 

Craig

Share this post


Link to post
Share on other sites
In your admin/loactions/zones. Make sure it is not there before adding it again. : )

 

Craig

:-"

Thank you zboyblue - that was so obvious it made me feel stupid. Kind of a slap the forehead type moment. It was missing, so I added it easy as pie. Wish all my problems with oscommerce were that easy to solve. Thanks again!

Mike

Share this post


Link to post
Share on other sites

Hehe ... well I have had PLENTY of those moments. It is not very often that I get to answer someone ELSE's question so I do so when I can gladly. : )

 

Good luck with everything.

 

Craig

Share this post


Link to post
Share on other sites

hi steve

 

thanks for this great contrib.

 

one small problem i have at the moment is upon account creation i get the following error

 

1062 - Duplicate entry '5' for key 1

 

insert into customers_info (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('5', '0', now())

 

[TEP STOP]

 

 

now i know this has to do with the referral contrib and you had an answer for it, which i did not understand...

 

"Interesting. I'll poke at this tonight and see what I can figure out. In the meantime, search includes/functions for tep_get_source_list and make sure you are INCLUDEing the file that defines it. My guess is that it's a function that is added as part of the other contribution and you need to make sure it is defined."

 

sorry to sound so dumb, but which file do i look at?

 

:'(

 

mike

Share this post


Link to post
Share on other sites

I'm sorry for the delay in responding - I did not get notified of new replied until late today.

 

Craig, the modification to the <body> tag is optional - all it does is set focus to the State field on a refresh. This is just a "1+" that can be easily discarded without affecting the functionality of this contribution.

 

Regarding the templates - I'm sorry, I don't use templates, so I am not very familiar with their operation.

 

Martin, see above comment. I have not seen an issue with the focus() call - admittedly it doesn't seem to do anything when the state is a drop-down list - but as I mentioned above, it can be removed without harm.

 

Mike, I don't think my response that you quoted is relevant to that problem. The error you are having is not related to C-S Selector which doesn't modify that code at all. What is happening is that your code is trying to add a new record with a customer ID that already exists. I'm not sure how that happened, because a little bit earlier the customer record was created and the insert_id fetched. So I'd guess that some other contrib modified this code.

Share this post


Link to post
Share on other sites

Mike, I don't think my response that you quoted is relevant to that problem. The error you are having is not related to C-S Selector which doesn't modify that code at all. What is happening is that your code is trying to add a new record with a customer ID that already exists. I'm not sure how that happened, because a little bit earlier the customer record was created and the insert_id fetched. So I'd guess that some other contrib modified this code.

 

:rolleyes: Thanks for getting back to me Steve, but someone else saw my post and steared me in the right direction. It was just a matter of checking in the admin section, noticing FL was actually missing, and then simply adding it to the data base. So easy I felt dumb. Anyway, its a solved problem. Thanks again

Mike

Share this post


Link to post
Share on other sites
Mike, I don't think my response that you quoted is relevant to that problem.  The error you are having is not related to C-S Selector which doesn't modify that code at all.  What is happening is that your code is trying to add a new record with a customer ID that already exists.  I'm not sure how that happened, because a little bit earlier the customer record was created and the insert_id fetched.  So I'd guess that some other contrib modified this code.

 

Hi Steve

 

You are correct, it had nothing to do with your contrib, i have fixed it now and dont get the error. The customer info was being entered into the db twice.

 

But i have come across another problem now :'(

 

I can create a new customer with no problems at all, but when i go to address_book.php there is no address there, and when i go to add an address i get an error "Parse error: parse error, unexpected $ in address_book_process.php on line 425" now line 425 is "<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>" which seems strange.

 

I dont think that when a customer creates an account the address is not being passed as the "primary address" this would explain why no address appears when you go to address_book.php.

 

I removed all of your changes made to address_book_process.php and was then able to go and add a new address, at the bottom it has the tick box for "primary address" but previously the original address when set up would have been the primary address.

 

I then went and added back all your changes to address_book_process.php went to address book and could see the primary address, if i click edit i get the same error as above "Parse error: parse error, unexpected $ in address_book_process.php on line 425"

 

I have only 1 country (UK) but have loads of countys, also i have only aloud there to be 1 address entry only also i removed the "please select" from the dropdown in the country field.

 

Hope you can help me out here.

 

Thanks

 

Mike

Share this post


Link to post
Share on other sites

This was touched on a little bit in the past, but I didn't see anything specific on how to achieve this. I would like to be able to set the default state to something other than Alabama since most of my orders will be coming from Illinois. Is setting the default state done in code, through the admin area, database, etc.? If anyone has done this and can give me the details, please let me know.

 

Thanks,

Zickarena

Share this post


Link to post
Share on other sites

Grr - I'm not getting notifications of replies to this topic again...

 

Mike, I would suggest that you look at includes/modules/address_book_details as well. Compare your files against the pre-edited versions I provide in the ZIP file and see what's different.

 

Zickarena, it is just picking the first zone in the list. In create_account.php, find the line:

          echo tep_draw_pull_down_menu('state', $zones_array);

Change it to:

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

If there happens to be a zone named Illinois in some other country, then that will get selected too if that country is chosen, but I think you're pretty safe there.

Share this post


Link to post
Share on other sites

Hi Steve

 

Is there anyway that the country whose currency is selected can be the first on in the country dropdown list?


The Coopco Underwear Shop

 

If you live to be 100 years of age, that means you have lived for 36,525 days. Don't waste another, there aren't many left.

Share this post


Link to post
Share on other sites

If you can figure out the correlation, sure. Find the lines which say:

    if (!isset($country)) $country = DEFAULT_COUNTRY;

and change them to set whichever country code you want. The Currencies table does not have a field for country, so perhaps you could add one.

Share this post


Link to post
Share on other sites
Mike, I would suggest that you look at includes/modules/address_book_details as well.  Compare your files against the pre-edited versions I provide in the ZIP file and see what's different.

 

Hi Steve

 

Thanks, all ok now :D i had deleted the code that updated the address book :blush:

 

Just another day in the PHP world. :-"

 

Quick question tho, how can i remove the dropdown for the country, i only have one so have no need for the drop down. Just pure text appearing where the customer cannot alter.

 

Thanks Again :thumbsup:

 

Mike

Share this post


Link to post
Share on other sites

Well, the simplest way is to remove all the countries from the "countries" table except the one you want. An alternative is to replace:

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

with:

<?php // +Country-State Selector ?>
<td class="main"><?php echo tep_draw_hidden_field('country',$country) . 'United States '; ?></td>
<?php // -Country-State Selector ?>

or something like this...

Share this post


Link to post
Share on other sites

Hi Steve

 

Thank you very much, i made the changes in creat_account and that works perfectly :thumbsup:

 

Now i made the same change to includes/modules/address_book_details and the country now appears as text :thumbsup: but if i try and edit the address details it will give an error "You must select a country from the Countries pull down menu." :(

 

Can you let me know where i need to make the change for it to work correctly?

 

Once again, thank you for all your help with this.

 

P.S. A donation will be on its way soon.

 

Cheers :thumbsup:

 

Mike

Share this post


Link to post
Share on other sites

In address_book_details.php, the code you want instead is:

<?php // +Country-State Selector ?>
<td class="main"><?php echo tep_draw_hidden_field('country',$entry['entry_country_id']) . 'United States '; ?></td>
<?php // -Country-State Selector ?>

Share this post


Link to post
Share on other sites

Hey there,

 

I tried editing the code, and it dosent want to work for me.

It displays the Country name correctly, but dosent display the area drop-downs.

 

I've cleared all other countries out of my db, apart from the United Kingdom, and i put this line of code in create_account.php:

        <td class="main"><?php echo tep_draw_hidden_field('country',$country) . 'United Kingdom '; ?>

 

Any ideas on why it's not working???

 

Cheers

Fatmcgav

 

Well, the simplest way is to remove all the countries from the "countries" table except the one you want.  An alternative is to replace:

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

with:

<?php // +Country-State Selector ?>
<td class="main"><?php echo tep_draw_hidden_field('country',$country) . 'United States '; ?></td>
<?php // -Country-State Selector ?>

or something like this...

Share this post


Link to post
Share on other sites

ok two things

 

you have added this?

 

// +Country-State Selector

define ('DEFAULT_COUNTRY', '222');

// -Country-State Selector

 

next, you do have countys/states defined in your database for the UK ie.. middlesex,herts etc....

 

cheers

Share this post


Link to post
Share on other sites

As far as i know, it's set as def.

 

I've managed to sort it in create_account.php by changing this code:

 // +Country-State Selector 
}
if ($HTTP_POST_VARS['action'] == 'refresh') {$state = '';}
if (!isset($country)){$country = 222;}
// -Country-State Selector

 

However, i cant see a similar line in address_book_details.php to change. Any ideas what i need to do there?

 

Cheers

Fatmcgav

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

×