Jump to content

Recommended Posts

17 hours ago, raiwa said:

I don't know why it doesn't show the error. Maybe it's because the script is accessed via javascript? But if 'state_name' is not in the array listed, it is not set and doesn't exist.

Meanwhile it's always better to echo variables where they are used:


  require('includes/application_top.php');

  echo '$_POST' . print_r($_POST);
  $country_id = $_POST['country_id'];
  $state_name = $_POST['state_name'];

  $check_query = tep_db_query("select count(*) as total from zones where zone_country_id = '" . (int)$country_id . "'");

 

echo '$_POST' shows $_POST as text (I think you have made a mistake).
echo $_POST shows Array

Eventually, echo $_POST['state_name'] shows the variable selected result (13).

print_r($_POST) shows the array : Array ( [country_id] => 21 [state_name] => 13 )

NB: print_r($_POST) don't need echo to be displayed.

 

Frankly it's a lot of quibbles for not much ...

If I write it this way it looks better for you ? :

echo tep_draw_input_field('state', (isset($state_name) ? $state_name : ''), 'id="inputState" placeholder="' . ENTRY_STATE_TEXT . '"');

 


Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Share this post


Link to post
Share on other sites

I do the text echo to see where it is displayed even there is no variable content, it's just my habit.

I would say correct is to apply the isset check where the ·POST variable is used:

  $state_name = (isset($_POST['state_name']) ? $_POST['state_name'] : '');

$state name is always defined in your code, no need to check it in the menu.

Share this post


Link to post
Share on other sites
Quote

1. For those who has got 2.3.4.1 CE Frozen version and/or fontawesome 5 :

Edit includes/modules/header_tags/ht_country_state_jquery.php file and find this code :

I have no such file.  I am using 2.3.4.1 CE

Downloaded and installed on May 26th.  Do I need to upgrade already?  :ohmy:

I've installed this contribution and I have no dropdown box for the state field at all.  Only the country.

Please advise!

- Andrea

Share this post


Link to post
Share on other sites

Hello Milerwan - great little contribution .... almost solved my requirement out of the box .... but ... works fine in create_account.php but when I try to add a new address to an account ie using address_book_process.php the spinner runs but I get no states pull down, only an empty input box. Not sure where to start looking for the problem but I have installed a mint version of address_book_process.php and address_book_details.php from osCommerce 234 Bootstrap Master. Any ideas?

Thanks

Share this post


Link to post
Share on other sites
On 5/16/2019 at 12:19 PM, kdenby said:

Hello Milerwan - great little contribution .... almost solved my requirement out of the box .... but ... works fine in create_account.php but when I try to add a new address to an account ie using address_book_process.php the spinner runs but I get no states pull down, only an empty input box. Not sure where to start looking for the problem but I have installed a mint version of address_book_process.php and address_book_details.php from osCommerce 234 Bootstrap Master. Any ideas?

Thanks

From "admin -> Modules -> Header Tags -> Country/States Selector", you have to edit the module and tick the missing page(s) to apply the script :
address_book_process.php
checkout_payment_address.php
checkout_shipping_address.php
create_account.php

Edited by milerwan

Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Share this post


Link to post
Share on other sites

Thanks for getting back to me ... but .. I had already made those selections in the module. The state selector pulldown appears fine in a new account - ie create_account.php but once an account is created then adding a new address or editing the already created one has no pulldown (though the spinner runs on program launch) - see screenshots below.

Cheers

edit_address.jpg

new_account_address.jpg

module_settings.jpg

Share this post


Link to post
Share on other sites

I want to run this on every page load.

 

I am using :

$(document).ready(function(){
  if($("#inputCountry").val()==""){
    $("#inputCountry").val('223');
  }
    if($("#inputCountry").val()!=""){
      $("label[for='inputState']+div").html('<i class="fa fa-spinner fa-spin fa-2x fa-fw" style="margin-top:2px; margin-bottom:9px; margin-left:0px;"></i>'),id_country=$("#inputCountry").val(),$.post("states.php",{country_id:id_country,state_name:sn},function(a){
        $("label[for='inputState']+div").html(a)
        }
      )
    }
  });

 

The state does not change from USA to Canada.

I have put the script below the drop downs in the code. 

Not sure why it is not though, is there a specific BS version I need to be using or some tool in the BS release?

 


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites

This is the form input I am using:

 

<div class="md-form pb-3">
	<div class="form-group has-feedback">
	<label for="inputState" class="control-label col-sm-6">State/Province:</label>
	<select name="state"  placeholder="Enter State" required aria-required="true" aria-describedby="atState" id="inputState" class="form-control validate white-text" >
<option value="1">Alabama</option><option value="2">Alaska</option><option 		value="4">Arizona</option><option value="5">Arkansas</option><option value="12">California</option><option value="13">Colorado</option><option value="14">Connecticut</option><option value="15">Delaware</option><option value="16">District of Columbia</option><option value="18" selected="selected">Florida</option><option value="19">Georgia</option><option value="21">Hawaii</option><option value="22">Idaho</option><option value="23">Illinois</option><option value="24">Indiana</option><option value="25">Iowa</option><option value="26">Kansas</option><option value="27">Kentucky</option><option value="28">Louisiana</option><option value="29">Maine</option><option value="31">Maryland</option><option value="32">Massachusetts</option><option value="33">Michigan</option><option value="34">Minnesota</option><option value="35">Mississippi</option><option value="36">Missouri</option><option value="37">Montana</option><option value="38">Nebraska</option><option value="39">Nevada</option><option value="40">New Hampshire</option><option value="41">New Jersey</option><option value="42">New Mexico</option><option value="43">New York</option><option value="44">North Carolina</option><option value="45">North Dakota</option><option value="47">Ohio</option><option value="48">Oklahoma</option><option value="49">Oregon</option><option value="51">Pennsylvania</option><option value="53">Rhode Island</option><option value="54">South Carolina</option><option value="55">South Dakota</option><option value="56">Tennessee</option><option value="57">Texas</option><option value="58">Utah</option><option value="59">Vermont</option><option value="61">Virginia</option><option value="62">Washington</option><option value="63">West Virginia</option><option value="64">Wisconsin</option><option value="65">Wyoming</option></select>			  
  
  </div>
</div>
<div class="md-form pb-3">
	<div class="form-group has-feedback">
	<label for="inputCountry" class="control-label col-sm-6">Country:</label>
	<select name="country" required aria-required="true" aria-describedby="atCountry" id="inputCountry"><option value="" selected="selected">Please Select</option><option value="38">Canada</option><option value="223">United States</option></select>			
  </div>
</div>

 


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites
2 hours ago, cannuck1964 said:

$(document).ready(function(){

Try replacing the above with this


 window.addEventListener('DOMContentLoaded', function() { //wait for jquery to load

 

Share this post


Link to post
Share on other sites

Thanks Jack, no did not work. 

I might just move past it, as my guess it is a conflict somewhere.  I have a lot of JS on the site, looking to actually move all cart functions to AJAX calls.

I use a lot of modals to login, create accounts etc. 

cheers

Peter


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites

@cannuck1964If you haven't done so I suggest you enable the developer console for your browser so that you can see why the code is failing. The code I mentioned is needed in the newer shops because jquery isn't loaded until the end. But it might be that you have some minor mistake in the code, or something like that.

Share this post


Link to post
Share on other sites

I have the developer module running.  did not think this would be a hard contribution to install, but this is the error :

Uncaught ReferenceError: sn is not defined
    <anonymous> https://dev.mrboxonline.com/quote_history.php:127

 

Coming from this code:

window.addEventListener('DOMContentLoaded', function() {
  if($("#inputCountry").val()==""){
	$("#inputCountry").val('223');
  }
	if($("#inputCountry").val()!=""){
	  $("label[for='inputState']+div").html(''),id_country=$("#inputCountry").val(),$.post("states.php",{country_id:id_country,state_name:sn},function(a){
		$("label[for='inputState']+div").html(a)
		}
	  )
	}
  });

 

sn (state name) is not defined for some reason.

 

cheers

Peter

 

 


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites

And adding in the line:

  var sn=$("#inputState").val();

does not help.

cheers

Peter

 

 


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites

@cannuck1964 The developer consoles will return not defined for a number of reasons, not all of which have to do with what the error says. I think the problem is that this line doesn't have closure

		$("label[for='inputState']+div").html(a)

and/or there is an extra } after it.

When I get such a failure on a js function, I delete everything in it and just include an alert or console.log line. If the message shows up then you know the calling function is working. Then add in parts of the original code to see where it fails.

Share this post


Link to post
Share on other sites
Quote

sn (state name) is not defined for some reason.

give this a try:

window.addEventListener('DOMContentLoaded', function() {
    if ($("#inputCountry").val() == "") {
        $("#inputCountry").val("223");
    }
    if ($("#inputCountry").val() != "") {
        $("label[for='inputState']+div").html(),
            (id_country = $("#inputCountry").val()),
            (sn = $("#inputState").val()),
            $.post("states.php", { country_id:id_country, state_name:sn }, function (a) {
                $("label[for='inputState']+div").html(a);
            });
    }
});

 

 

 


osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Share this post


Link to post
Share on other sites

Thanks Demitry, but no, that does not work either.

Normally I do not have a lot of issues with javascript, but this one is just not quite right.  I suspect a conflict somewhere.


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Share this post


Link to post
Share on other sites

@cannuck1964

What version of osC are you using? And, did you just install this add-on, or was it there from some time back and just stopped working?

I have BS Edge and the default code for the country/state pairing was problematic. I actually worked on this Country State Selector add-on, but for reasons I cannot recall now, I chose a different one.

I installed Rainer's State Selector BS add-on and World Zones.

https://apps. oscommerce.com/cbtGB&state-selector-bs

 

 


osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Share this post


Link to post
Share on other sites

My version of osC is 2.3.4++

I do a lot of upgrades and do not follow all of the osC releases.

Tried the new one and same thing, no luck.  I think I will try upgrading my jQuery and bootstrap versions, maybe that will help, not sure when I did so last.

thanks

Peter

 

 

 


Peter McGrath

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

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

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

×