Jump to content
stevel

Country-State Selector

Recommended Posts

Interesting - I don't see this problem myself. What browser are you using? I'd have to study the code again (and I'm at work at the moment), but I don't see why it should be necessary to reset the dropdown list, which in fact should be ignored on the refresh. I'll have to take a closer look.

Share this post


Link to post
Share on other sites

Thanks!

 

That code works great, I myself am using Mac IE 5.2. I havent tried to reproduce the problem on any other browsers.

 

Thanks again,

 

KennethS


Kenneth S

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

Customer "Are you a real programmer?"

Me "No, but I did stay at a Holiday Inn Express last night"

Share this post


Link to post
Share on other sites

I'm using firefox 0.9 on linux at this point, but this bug appears in firefox 0.9 on windows as well. I'm going to double check for this bug in opera and ie... I don't understand why the value of the state field isn't ignored on refresh, since the field type is changing...

 

Alright, testing in opera shows that it doesnt have the problem at all... Whether the refresh_form js function is same as original, or changed according to my last post, they both work properly...

 

Testing is showing the same results in ie as in opera. Both ie and opera don't have the problem, but the fix doesn't cause any harm (no js errors that i saw), and takes care of the problem on firefox 0.9.

Share this post


Link to post
Share on other sites

I don't see the problem with Firefox 0.8 on Windows. At the moment, I'm baffled by this but will be glad to look into it further. Sounds like a browser bug to me at the moment.

Share this post


Link to post
Share on other sites

I've actually been looking into this a little bit more and recoded the function so it can be reused by anyone who needs a refresh form function. It also checks for the existence of the state field and only wipes it clean if it fits the parameters needed for the country-state selector. I've tested it cross-platform on ie, opera and firefox 0.9. It might be a little overkill, but take a look and see what you think...

 

<?php // +Country-State Selector ?>
function refresh_form(form_name) {
  form_name.action.value = 'refresh';

  if (testIsValidObject(form_name.state))
  {
    if (form_name.state.type == 'text')
    {
       form_name.state.value = '';
    }
    else if (form_name.state.type == 'select-one')
    {
       for (var i=form_name.state.options.length-1; i>=0; i--)
       {
          form_name.state.options[i] = null;
       }
       form_name.state.selectedIndex = -1;
    }
  }

  form_name.submit();
  return true;
}

function testIsValidObject(objToTest) {
  if (null == objToTest) {
    return false;
  }
  if ("undefined" == typeof(objToTest) ) {
    return false;
  }
  return true;
}
<?php // -Country-State Selector ?>

Share this post


Link to post
Share on other sites

Is there a way to pull this same style contrib, or add on to this contrib and have it not reload the page? Im on DSL and the https login doesnt really bother me but Im thinking of the poor 56kers having to reload that page.


Kenneth S

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

Customer "Are you a real programmer?"

Me "No, but I did stay at a Holiday Inn Express last night"

Share this post


Link to post
Share on other sites

I doubt it to tell you the truth, because each time a new country is selected, it has to get information about that country and its zones from the database on the server using php. You could somehow create a flat file database with the states (which wouldn't be too bad because only Germany, Canada and the US have states in the database to my knowledge) and use javascript to manipulate what options are displayed in the states field when those particular countries are selected. However, that would be pretty hardcore and would require ensuring the data being manipulated by javascript is related properly back to oscommerce. Not impossible, but it would require a fair bit of work...

Share this post


Link to post
Share on other sites

I thought about this, but it's VERY hard to make it work where some countries have "states" and some don't. The actual page contents aren't very bandwidth intensive, unless you have lots of junk in the header or columns.

 

To be honest, if you did load a big array and have JS code to manipulate it, EVERY load of the page would have to send the whole state list for all countries, and that would probably be more painful than the current method.

Share this post


Link to post
Share on other sites

Ok, I installed Firefox 0.9 and I can reproduce the problem there. Very strange. I'm guessing that Firefox rejects the clearing of the state field of the form when it is a dropdown rather than a text field.

 

Thanks for the fix- I'll incorporate it.

Share this post


Link to post
Share on other sites

When using this mod (Country-State Selector 1.0.5) I have a problem in admin.

That is when viewing orders the country shows as array as opposed to the country name.


It ain't your grandma's box!

Share this post


Link to post
Share on other sites

Hi,

 

I have just installed this contribution. All seems to working fine.

 

Thanks to all those invloved - great contribution!

 

Simon.


Gynogapod - Great Products, Tiny Prices!

Share this post


Link to post
Share on other sites

hi, i've installed this mod and everything seems to be working fine. but after i've made some other changes to my files, i found out a problem. basically, what it does is that when u change the country from default country to some other country from the pull down, the page don't refreshes as it should. please advice. tia

khampaman

Share this post


Link to post
Share on other sites

sorry to bother u with same question, stevel! i didn't go through all the message. seems like many people are having similar problem as mine.

Share this post


Link to post
Share on other sites

The usual cause of this, I have found, is that people have added a contribution, typically a template system, that makes two copies of the form_check_js.php file. They edit one of them, per my instructions, but their code has been changed to reference the other.

 

The way to tell if this is the case is to bring up the create account page in a browser, then do a "view source". Search the HTML source for "function refresh_form". If you don't find it, that's the problem. Make the edit in the copy of form_check_js.php that is actually being referenced.

Share this post


Link to post
Share on other sites

stevel, i checked the refresh function. couldn't find it. can u explain to me in detail how to fix this. i would really appreciate it. i could send you the necessary or post it here. tia

Share this post


Link to post
Share on other sites

Hi Steve,

Your contribution could be just what I need. I sell only in the United Kingdom and I am using 2checkout as my payment gateway. My question is can I set up country State selector to select Outside US and Canada in the state box when I select United Kingdom as the country when setting up new accounts. This means when people pay via 2checkout they go straight to the payment page on 2checkout and bypass the shipping page.

Share this post


Link to post
Share on other sites

Tashi,

 

One of the files this contribution has you edit is catalog/includes/form_check.js.php - you are to add a function called refresh_form. The file is used from create_account.php and address_book_process.php with the following line:

<?php require('includes/form_check.js.php'); ?>

 

I have seen that at least one of the "templates" contributions changes this line to reference a different copy of form_check.js.php - one perhaps supplied by the template contribution. The simplest thing to do is to find that file and add the refresh_form function there too.

Share this post


Link to post
Share on other sites

Andrew,

 

Sure, you can do that. If you do nothing else other than install C-S Selector in a stock install, and you set DEFAULT_COUNTRY to 222 (for UK), then the State field will display as blank text for the customer to fill in.

 

I can tell you how to make "Outside US and Canada" appear as a UK zone, but this has other side effects that you probably don't want. There are other ways to approach this.

 

Since you sell to the UK only, this contribution is overkill for you. What you want instead is to simply hardwire 222 as the country code and set the state to "Outside US and Canada". This is just a couple of lines of PHP in create_account.php and address_book_process.php. You can then replace the code in create_account and address_book_details.php (in includes/modules) to not display the country or state selection items in the form.

 

You'll have to figure out how to prevent what you have set for the state from being shown to the customer as part of their address. I'm not familiar with 2checkout to advise you on what you need to change where for that.

Share this post


Link to post
Share on other sites

steve,

i don't have template contribution. i'm totally lost, i tried your suggestion but i couldn't nail down the problem. i've pm'd u those two files. can u please have a look at those, i would really appreciate it. thanks alot for your help.

Share this post


Link to post
Share on other sites

Ok, your problem is something else.

 

First, I notice that your page has syntax errors in the JavaScript, apparently because ENTRY_TELEPHONE_MIN_LENGTH is undefined. This ought to be set in admin under "Minimum Values".."Telephone Number". Odd that it is coming up empty. If you want no minimum length, set it to 0.

 

The other thing I suggest is to replace the code I have you add in form_check.js.php with the following:

<?php // +Country-State Selector ?>
function refresh_form(form_name) {
 form_name.action.value = 'refresh';

 if (testIsValidObject(form_name.state))
 {
   if (form_name.state.type == 'text')
   {
      form_name.state.value = '';
   }
   else if (form_name.state.type == 'select-one')
   {
      for (var i=form_name.state.options.length-1; i>=0; i--)
      {
         form_name.state.options[i] = null;
      }
      form_name.state.selectedIndex = -1;
   }
 }

 form_name.submit();
 return true;
}

function testIsValidObject(objToTest) {
 if (null == objToTest) {
   return false;
 }
 if ("undefined" == typeof(objToTest) ) {
   return false;
 }
 return true;
}
<?php // -Country-State Selector ?>

 

This will fix a problem with Firefox, though it's unrelated to your problem.

 

I don't know for sure if the above will help, but it's a start.

Share this post


Link to post
Share on other sites

Hi Steve,

 

thank you very much for replying to my question.

 

As you can no doubt tell from my questions below I need some time to understand php at your level. I understand if these requests are unreasonable and you are unable to help. The reply you have already given has pointed me in the right direction and how to proceed, however I will ask anyway.

 

Can you tell me how to hardwire 222 as the country code and set the state to "Outside US and Canada"?

 

What would the couple of lines of PHP in create_account.php and address_book_process.php be to achieve this?

 

What do I replace in the code in create_account and address_book_details.php (in includes/modules) to not display the country or state selection items in the form?

 

Again many thanks for your help

 

Andrew

Share this post


Link to post
Share on other sites

I can get you started. I am NOT a PHP expert, but I have been dabbling in it for enough months to get by. It helped that I bought and read a good book on PHP, "Programming PHP" from O'Reilly Press.

 

First, in Admin, Configuration, Customer Details, set State and Suburb to False. This means you won't be asking for inputs for those.

 

In create_account.php, replace the following code:

              <tr>
               <td class="main"><?php echo ENTRY_COUNTRY; ?></td>
               <td class="main"><?php echo tep_get_country_list('country') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>
             </tr>

with

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

You would make the same change in address_book_details.

 

Now simply change the code that deals with 2checkout to pass whatever you want for state, since the order will no longer have a state field.

 

If you need further help with this, ask in the general support section of the forum.

Share this post


Link to post
Share on other sites

Thanks Steve,

 

I'll go and do that and let you know. Appreciate your time on this, much appreciated.

 

Andrew

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

×