Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

State Selector for BS


raiwa

Recommended Posts

Support forum for State Selector for osc 2.3.4 BS Version 1.0 by @raiwa

based on the code posted by @@De Dokta
http://www.oscommerce.com/forums/topic/397121-drop-down-state-selection-and-2334bs3/?p=1724667

This add-on will show a state drop down menu in "create account", address_book" and "checkout_new_address".

Download:

http://addons.oscommerce.com/info/9309

Edited by raiwa
Link to comment
Share on other sites

Hi  Raiwa,

Thanks for a much needed module.

I have installed this several times on two test sites both running 234BS and am encountering these problems:

  • The create account page is not loading after the nav bar & headers
  • The new address book entry and edit works  -  but the red star moves to the right and covers the little down arrow in the State drop down
  • Can the state dropdown be made to work on this when editing the customers address in admin?

Any assistance with this will be appeciated.

Thanks

Tom

Link to comment
Share on other sites

Hello Tom @@Artisan Foundry,

 

Thank you for the feedback.

 


The create account page is not loading after the nav bar & headers

I checked both, modifying the file by instructions and using the file of the package and both are working in my teststore.

My base is the 2.3.4 bs master package from 24 of february 2015.

Please try first if the included create_account file works. If yes, you may have an error in your file, compare both and check for missing/wrong code.

If you modified your file you may need to adapt the modifications for your need. To find the error you may have a look in your error log if you have error reporting switched off.

 

The new address book entry and edit works  -  but the red star moves to the right and covers the little down arrow in the State drop down

 

I observed this too and couldn't find an elegant way to get it solved. When I checked now create account I found that it's correct in it's place. Curious, no idea why, in the other forms it's still showing moved.

Here a "dirty" fix:

            		echo '<span style="position:relative; right:7px; top:-8px;">' . FORM_REQUIRED_INPUT . '</span>';

In any case I removed all these red stars in my forms and also the placeholder in the required fields. I'm using placeholder "optional" for the optional fields. Like this the forms look much cleaner and calmer and the users do not get "alarmed" by all these red stars :)

 

 

Can the state dropdown be made to work on this when editing the customers address in admin?

- copy the javascript from ht_get_states.php to the admin template_bottom.php

- place a copy of catalog/get_states.php into your admin root

- apply the changes from address_book_details.php to admin/customers.php

 

Admin area is not bootstrapped yet, so you may need to remove the bootstrap tags from the label and fields.

Just try

 

regards

Rainer

Edited by raiwa
Link to comment
Share on other sites

Artisan Foundry, on 12 May 2015 - 21:20, said:snapback.png

The new address book entry and edit works  -  but the red star moves to the right and covers the little down arrow in the State drop down

 

There's a <div class="form-group"> in address_book_details.php. Change it to <div class="form-group has-feedback"> and the asterix will be in the right place.

 

J.J.

Link to comment
Share on other sites

Hi Rainer,

Thanks for the quick response and explanation.

I am not a programmer so apologies for needing some further information.

  • I now have the create-account working by pasting the code into my own .php file as suggested :D
  • The "dirty" fix  you have shown -  1) what file do I put it in?    2) What line is it on?   3) Does it replace a line or is it new code? 

I understand what you mean about the red stars they are very alarming.

Kind regards

Tom

Link to comment
Share on other sites

 

Artisan Foundry, on 12 May 2015 - 21:20, said:snapback.png

 

There's a <div class="form-group"> in address_book_details.php. Change it to <div class="form-group has-feedback"> and the asterix will be in the right place.

 

J.J.

 

Hi J.J,

My state drop down is working and displaying as it should.

Thank you!

Kind regards

Tom

Link to comment
Share on other sites

Hi looks like a great package.  Should be part of BS.

 

I'm not live yet with BS.  But working on it.  I installed the modifications and received the following errors.

 

Warning: require(includes/form_check.js.php): failed to open stream: No such file or directory in /home/ladybug3597/public_html/osc234/create_account.php on line 290

Warning: require(includes/form_check.js.php): failed to open stream: No such file or directory in /home/ladybug3597/public_html/osc234/create_account.php on line 290

Fatal error: require(): Failed opening required 'includes/form_check.js.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ladybug3597/public_html/osc234/create_account.php on line 290
 

 

create_account.php line 290 is   require('includes/form_check.js.php');

 

What do I need to do to fix this?

Thanks

Dean

Link to comment
Share on other sites

  • 2 weeks later...

@@sheepiedog,

 

Yes, it is done like this. It is supposed to be more logic, due to the content of the state menu will change when the country is changed. If you wish you can move the country part below the state selector, it will work. But then I would recommend to add some text like "The "State" drop-down list will be updated when you change the Country".

 

regards

Rainer

Link to comment
Share on other sites

Thanks raiwa

 

I have tried and tried different scenarios.  I only use United States and so my customers will not be changing countries. I really need the state selector to prevent misspellings and to make the address forms more user friendly.  I am trying to put it in this order: city, state, zip code and then country. When I try to move the country down to the bottom after the zip codes </div></div> , the state is no longer a drop down menu.

 

I am obviously doing something incorrectly - would you be able to point me in the right direction ?

      <div class="form-group has-feedback">
        <label for="inputCity" class="control-label col-sm-3"><?php echo ENTRY_CITY; ?></label>
        <div class="col-sm-9">
          <?php
          echo tep_draw_input_field('city', (isset($entry['entry_city']) ? $entry['entry_city'] : ''), 'required aria-required="true" id="inputCity" placeholder="' . ENTRY_CITY. '"');
          echo FORM_REQUIRED_INPUT;
          if (tep_not_null(ENTRY_CITY_TEXT)) echo '<span class="help-block">' . ENTRY_CITY_TEXT . '</span>';
          ?>
        </div>
      </div>

<?php
  if (ACCOUNT_STATE == 'true') {
?>

      <div class="form-group">
        <label for="inputState" class="control-label col-sm-3"><?php echo ENTRY_STATE; ?></label>
        <div class="col-sm-9">
          <?php
      			$zone_id = 0;
      			$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . $country . "'");
      			$check = tep_db_fetch_array($check_query);
      			$entry_state_has_zones = ($check['total'] > 0);
            	if ($entry_state_has_zones == true) {
            		$zones_array = array();
            		$zones_array[0] = array('id' => '0', 'text' => PULL_DOWN_DEFAULT);                        
            		$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']);
            		}
            		echo '<span id="results">';
            		echo tep_draw_pull_down_menu('state', $zones_array, (isset($entry['entry_country_id']) ? tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']) : ''), 'id="inputState"');
            		echo '</span>';
            		echo FORM_REQUIRED_INPUT;
            	} else {
            		echo '<span id="results">';
            		echo tep_draw_input_field('state', NULL, 'id="inputState" placeholder="' . ENTRY_STATE . '"');
            		echo '</span>';
            		echo FORM_REQUIRED_INPUT;
            	}
            	if (tep_not_null(ENTRY_STATE_TEXT)) echo '<span class="help-block">' . ENTRY_STATE_TEXT . '</span>';
          	?>
        </div>
      </div>
      <div class="form-group has-feedback">
        <label for="inputZip" class="control-label col-sm-3"><?php echo ENTRY_POST_CODE; ?></label>
        <div class="col-sm-9">
          <?php
          echo tep_draw_input_field('postcode', (isset($entry['entry_postcode']) ? $entry['entry_postcode'] : ''), 'required aria-required="true" id="inputZip" placeholder="' . ENTRY_POST_CODE . '"');
          echo FORM_REQUIRED_INPUT;
          if (tep_not_null(ENTRY_POST_CODE_TEXT)) echo '<span class="help-block">' . ENTRY_POST_CODE_TEXT . '</span>';
          ?>
       </div>
       </div>

<div class="form-group has-feedback">
<label for="inputCountry" class="control-label col-sm-3"><?php echo ENTRY_COUNTRY; ?></label>
<div class="col-sm-9">
<?php
$country = 0;
if ( isset($entry['entry_country_id']) ) {
    $country = $entry['entry_country_id'];
} elseif (MODULE_HEADER_TAGS_GET_STATES_DEFAULT_COUNTRY == 'True') {
    $country = STORE_COUNTRY;
}
echo tep_get_country_list('country', $country, 'onChange="getState(this.value)" required aria-required="true" id="inputCountry"');
echo FORM_REQUIRED_INPUT;
if (tep_not_null(ENTRY_COUNTRY_TEXT)) echo '<span class="help-block">' . ENTRY_COUNTRY_TEXT . '</span>';
?>
</div>
</div>
      
<?php
  }
?>

Link to comment
Share on other sites

Hello Deb @@sheepiedog,

 

Yes you are right. It was my fault. Forgot that the country definition needs to be above the state section.

So it should be:

      <div class="form-group has-feedback">
        <label for="inputCity" class="control-label col-sm-3"><?php echo ENTRY_CITY; ?></label>
        <div class="col-sm-9">
          <?php
          echo tep_draw_input_field('city', (isset($entry['entry_city']) ? $entry['entry_city'] : ''), 'required aria-required="true" id="inputCity" placeholder="' . ENTRY_CITY. '"');
          echo FORM_REQUIRED_INPUT;
          if (tep_not_null(ENTRY_CITY_TEXT)) echo '<span class="help-block">' . ENTRY_CITY_TEXT . '</span>';
          ?>
        </div>
      </div>

<?php
  if (ACCOUNT_STATE == 'true') {
?>

      <div class="form-group has-feedback">
        <label for="inputState" class="control-label col-sm-3"><?php echo ENTRY_STATE; ?></label>
        <div class="col-sm-9">
          <?php
          $country = 0;
          if ( isset($entry['entry_country_id']) ) {
          	$country = $entry['entry_country_id'];
          } elseif (MODULE_HEADER_TAGS_GET_STATES_DEFAULT_COUNTRY == 'True') {
          	$country = STORE_COUNTRY;
          }
      			$zone_id = 0;
      			$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . $country . "'");
      			$check = tep_db_fetch_array($check_query);
      			$entry_state_has_zones = ($check['total'] > 0);
            	if ($entry_state_has_zones == true) {
            		$zones_array = array();
            		$zones_array[0] = array('id' => '0', 'text' => PULL_DOWN_DEFAULT);                        
            		$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']);
            		}
            		echo '<span id="results">';
            		echo tep_draw_pull_down_menu('state', $zones_array, (isset($entry['entry_country_id']) ? tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']) : ''), 'id="inputState"');
            		echo '</span>';
            		echo FORM_REQUIRED_INPUT;
            	} else {
            		echo '<span id="results">';
            		echo tep_draw_input_field('state', NULL, 'id="inputState" placeholder="' . ENTRY_STATE . '"');
            		echo '</span>';
            		echo FORM_REQUIRED_INPUT;
            	}
            	if (tep_not_null(ENTRY_STATE_TEXT)) echo '<span class="help-block">' . ENTRY_STATE_TEXT . '</span>';
          	?>
        </div>
      </div>
      <div class="form-group has-feedback">
        <label for="inputZip" class="control-label col-sm-3"><?php echo ENTRY_POST_CODE; ?></label>
        <div class="col-sm-9">
          <?php
          echo tep_draw_input_field('postcode', (isset($entry['entry_postcode']) ? $entry['entry_postcode'] : ''), 'required aria-required="true" id="inputZip" placeholder="' . ENTRY_POST_CODE . '"');
          echo FORM_REQUIRED_INPUT;
          if (tep_not_null(ENTRY_POST_CODE_TEXT)) echo '<span class="help-block">' . ENTRY_POST_CODE_TEXT . '</span>';
          ?>
       </div>
      </div>

      <div class="form-group has-feedback">
      	<label for="inputCountry" class="control-label col-sm-3"><?php echo ENTRY_COUNTRY; ?></label>
      	<div class="col-sm-9">
       		<?php
       		echo tep_get_country_list('country', $country, 'onChange="getState(this.value)" required aria-required="true" id="inputCountry"');
       		echo FORM_REQUIRED_INPUT;
       		if (tep_not_null(ENTRY_COUNTRY_TEXT)) echo '<span class="help-block">' . ENTRY_COUNTRY_TEXT . '</span>';
       		?>
       	</div>
      </div>
      
<?php
  }
?>  

But, if you only use the store country, you do not need the state selector at all!! :-

You can revert all state selector installation and just modify the original code like this:

    <div class="form-group has-feedback">
      <label for="inputCity" class="control-label col-sm-3"><?php echo ENTRY_CITY; ?></label>
      <div class="col-sm-9">
        <?php
        echo tep_draw_input_field('city', NULL, 'required aria-required="true" id="inputCity" placeholder="' . ENTRY_CITY. '"');
        echo FORM_REQUIRED_INPUT;
        if (tep_not_null(ENTRY_CITY_TEXT)) echo '<span class="help-block">' . ENTRY_CITY_TEXT . '</span>';
        ?>
      </div>
    </div>
<?php
  if (ACCOUNT_STATE == 'true') {
?>
    <div class="form-group has-feedback">
      <label for="inputState" class="control-label col-sm-3"><?php echo ENTRY_STATE; ?></label>
      <div class="col-sm-9">
        <?php
            $zones_array = array();
            $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . STORE_COUNTRY . "' order by zone_name desc");
            while ($zones_values = tep_db_fetch_array($zones_query)) {
              $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
            }
            echo tep_draw_pull_down_menu('state', $zones_array, 0, 'id="inputState"');
            echo FORM_REQUIRED_INPUT;
        if (tep_not_null(ENTRY_STATE_TEXT)) echo '<span class="help-block">' . ENTRY_STATE_TEXT . '</span>';
        ?>
      </div>
    </div>
<?php
  }
?>
    <div class="form-group has-feedback">
      <label for="inputZip" class="control-label col-sm-3"><?php echo ENTRY_POST_CODE; ?></label>
      <div class="col-sm-9">
        <?php
        echo tep_draw_input_field('postcode', NULL, 'required aria-required="true" id="inputZip" placeholder="' . ENTRY_POST_CODE . '"');
        echo FORM_REQUIRED_INPUT;
        if (tep_not_null(ENTRY_POST_CODE_TEXT)) echo '<span class="help-block">' . ENTRY_POST_CODE_TEXT . '</span>';
        ?>
     </div>
    </div>
    <div class="form-group has-feedback">
      <label for="inputCountry" class="control-label col-sm-3"><?php echo ENTRY_COUNTRY; ?></label>
      <div class="col-sm-9">
        <?php
        echo tep_get_country_list('country', STORE_COUNTRY, 'required aria-required="true" id="inputCountry"');
        echo FORM_REQUIRED_INPUT;
        if (tep_not_null(ENTRY_COUNTRY_TEXT)) echo '<span class="help-block">' . ENTRY_COUNTRY_TEXT . '</span>';
        ?>
      </div>
    </div>
  </div>

Just remove all countries except your store country from the database (you did this already I guess) :)

 

regards

Rainer

Edited by raiwa
Link to comment
Share on other sites

Thank you so much !  I was able to change 2 of the files and they are perfect.  I had trouble with checkout_new_address as it seemed to affect the radio buttons for choosing existing addresses - so I just chose to go with your original contribution file for this.   I am grateful for your help with this, and hopefully it will help others who would like to do the same as I did.

Link to comment
Share on other sites

  • 4 weeks later...

@@raiwa and  @@De Dokta

 

Rainer and JJ thanks for your work on this great add-on for Bootstrap.  I just installed it and everything works like a charm....there was just one small pause for the cause when I reached the following instruction....

 

Upload the following new files:
- new_files/catalog/
 
After looking at the files I realized that should be...
 
Upload the following new files:
- new_files/catalog/get_states.php
 
Just fyi and thanks again...
 
Dan

 

Link to comment
Share on other sites

Hello Dan @@Dan Cole,

 

Yes, thank you. WIll fix it in the next update.

 

rgds

Rainer

Edited by raiwa
Link to comment
Share on other sites

Hello Ray @@newburns,

 

The code needs to be added on the files where to use it. So the instructions for create_account.php will do it for account_pwa.php.

 

regards

Rainer

 

Just had a look onto your Repo. There is a newer KISS IT thumbnail version available which is more user friendly and has some new features:

http://addons.oscommerce.com/info/9206

 

Some of my other BS Add-Ons which may be interesting for your project:

http://addons.oscommerce.com/info/9301

http://addons.oscommerce.com/info/9291

http://addons.oscommerce.com/info/9066

http://addons.oscommerce.com/info/8057

http://addons.oscommerce.com/info/9299

Edited by raiwa
Link to comment
Share on other sites

@@raiwa

Hi Rainer,

nice addon!

Some code changes may be good for BS form control:
 

<?php
  if (ACCOUNT_STATE == 'true') {
?>
    <div class="form-group has-feedback">
      <label for="inputState" class="control-label col-sm-3"><?php echo ENTRY_STATE; ?></label>
      <div id="results" class="col-sm-9">
        <?php
        $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");
        $check = tep_db_fetch_array($check_query);
        $entry_state_has_zones = ($check['total'] > 0);
      
        if ($entry_state_has_zones == true) {
          $zones_array = array();
          $zones_array[0] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);                        
          $zones_query = tep_db_query("select zone_name from 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']);
            }
//            echo '<span id="results">';
            echo tep_draw_pull_down_menu('state', $zones_array, '', 'required aria-required="true" id="inputState"');
//            echo '</span>';
            echo FORM_REQUIRED_INPUT;
        } else {
//          echo '<span id="results">';
          echo tep_draw_input_field('state', NULL, 'id="inputState"  class="form-control" placeholder="' . ENTRY_STATE    . '"');
//          echo '</span>';
//          echo FORM_REQUIRED_INPUT;
        }
        if (tep_not_null(ENTRY_STATE_TEXT)) echo '<span class="help-block">' . ENTRY_STATE_TEXT . '</span>';
        ?>
      </div>
    </div>
<?php
  }
?>

If not state then I have conflict with ENTRY_STATE_MIN_LENGTH so I had to change it 0 in admin site.
 

This origin '0' value prevent the form controll here.

$zones_array[0] = array('id' => '0', 'text' => PULL_DOWN_DEFAULT);

It would be better empty '' id as exists in my example.


<span> tag is obsolate so you could use:
 

<div id="results" class="col-sm-9">


I dont see the onchange function in get_states.php tep_draw_pull_down_menu() function. Am I missing something?

I have found mixing text in ht_get_states.php
 

 

'The pages to add the Datepicker jQuery Scripts to.'

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

Hello @@Gergely,

 

Thank you for the suggestions.

The code parts you mention are based on the solution @De Dokta posted here:

http://www.oscommerce.com/forums/topic/397121-drop-down-state-selection-and-2334bs3/?p=1724667

 

I only packed them together to a add-on package, previous permission of De Docta, of course.

So I would prefer if you discuss the modifications with him before I include the suggestions to the add-on.

 

Kindest regards

Rainer

Link to comment
Share on other sites

Hello @@Gergely,

 

Thank you for the suggestions.

The code parts you mention are based on the solution @De Dokta posted here:

http://www.oscommerce.com/forums/topic/397121-drop-down-state-selection-and-2334bs3/?p=1724667

 

I only packed them together to a add-on package, previous permission of De Docta, of course.

So I would prefer if you discuss the modifications with him before I include the suggestions to the add-on.

 

Kindest regards

Rainer

 

Hi Rainer,

 

sorry I dont know the prerequisites.

 

He had passed to you the responsibility :)

 

http://www.oscommerce.com/forums/topic/397121-drop-down-state-selection-and-2334bs3/?p=1727767

 

 

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

 Hello @@Gergely,

 

Of course I do not escape responsability. I just didn't want to change the original code without the opinion of the original author who still keeps an eye on this add-on. See previous posts in this thread. :)

I'll have a look meanwhile and test your modifications.

 

 

Rainer

Link to comment
Share on other sites

Hello @@Gergely,

 

I had a time to check your suggested changes and they seem all good to me. Allthough the <span> tags are not obsolete and working well, I'll change it to your solution, it is less code and more elegant.

 

"onchange function" is not needed here. The script in ht_get_states.php is coded in a way that it works without. (Do not ask me why, that's de docta's secret :-))

 

I found that you commented out the "FORM_REQUIRED_INPUT;" below the input field. It's supposed that it's done for your store and not part of the change suggestions??

 

Thank you and kind regards

Rainer

Link to comment
Share on other sites

@@Gergely,

 

Just to be sure, this change should be applied also in "get_states.php" ??:

 

This origin '0' value prevent the form controll here.

$zones_array[0] = array('id' => '0', 'text' => PULL_DOWN_DEFAULT);

It would be better empty '' id as exists in my example.

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