Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    102
    Plugin Contributions
    0

    Default Only display states selection box when from a certain country

    Hi
    In tpl_module_create_account.php I want to declare an if-statement.
    If a customer chooses a certain country, display the state dropdown. Else, display nothing.

    Original 1.5.1 code:
    Code:
    <?php
      if (ACCOUNT_STATE == 'true') {
        if ($flag_show_pulldown_states == true) {
    ?>
    <label class="m-wrap" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE; ?></label>
    <?php
          echo zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($selected_country), $zone_id, 'id="stateZone"');
          if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' . ENTRY_STATE_TEXT . '</span>';
        }
    ?>
    
    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php } ?>
    <label class="m-wrap" for="state" id="stateLabel"><?php echo $state_field_label; ?></label>
    <?php
        echo zen_draw_input_field('state', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_state', '40') . ' id="state"');
        if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert" id="stText">' . ENTRY_STATE_TEXT . '</span>';
        if ($flag_show_pulldown_states == false) {
          echo zen_draw_hidden_field('zone_id', $zone_name, ' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      }
    ?>
    Example
    Code:
    <?php
    if (SELECTED_COUNTRY == 23) {
      if (ACCOUNT_STATE == 'true') {
        if ($flag_show_pulldown_states == true) {
    ?>
    <label class="m-wrap" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE; ?></label>
    <?php
          echo zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($selected_country), $zone_id, 'id="stateZone"');
          if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' . ENTRY_STATE_TEXT . '</span>';
        }
    ?>
    
    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php } ?>
    <label class="m-wrap" for="state" id="stateLabel"><?php echo $state_field_label; ?></label>
    <?php
        echo zen_draw_input_field('state', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_state', '40') . ' id="state"');
        if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert" id="stText">' . ENTRY_STATE_TEXT . '</span>';
        if ($flag_show_pulldown_states == false) {
          echo zen_draw_hidden_field('zone_id', $zone_name, ' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      }
    }
    ?>
    but I cannot figure out the selectors?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Only display states selection box when from a certain country

    The state dropdown will only show if there are states defined for that country. You can control the entire list of available "states" via Admin->Location/Taxes->Zone Definitions.
    No programming necessary.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,267
    Plugin Contributions
    3

    Default Re: Only display states selection box when from a certain country

    Quote Originally Posted by DrByte View Post
    The state dropdown will only show if there are states defined for that country. You can control the entire list of available "states" via Admin->Location/Taxes->Zone Definitions.
    No programming necessary.
    This is what I do... I put the COUNTRY selector ABOVE the STATE selector in tpl_modules_create_account.php .

    This means the visitor has to select COUNTRY first, which will then default the STATE to given states in the dropdown (if defined for their country).

    The ORIGINAL part of the code in tpl_modules_create_account.php looks like this:

    (From about line #45)

    PHP Code:
    <fieldset>
    <legend><?php echo TABLE_HEADING_ADDRESS_DETAILS?></legend>
    <?php
      
    if (ACCOUNT_GENDER == 'true') {
    ?>
    <?php 
    echo zen_draw_radio_field('gender''m''''id="gender-male"') . '<label class="radioButtonLabel" for="gender-male">' MALE '</label>' zen_draw_radio_field('gender''f''''id="gender-female"') . '<label class="radioButtonLabel" for="gender-female">' FEMALE '</label>' . (zen_not_null(ENTRY_GENDER_TEXT) ? '<span class="alert">' ENTRY_GENDER_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="firstname"><?php echo ENTRY_FIRST_NAME?></label>
    <?php echo zen_draw_input_field('firstname'''zen_set_field_length(TABLE_CUSTOMERS'customers_firstname''40') . ' id="firstname"') . (zen_not_null(ENTRY_FIRST_NAME_TEXT) ? '<span class="alert">' ENTRY_FIRST_NAME_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="lastname"><?php echo ENTRY_LAST_NAME?></label>
    <?php echo zen_draw_input_field('lastname'''zen_set_field_length(TABLE_CUSTOMERS'customers_lastname''40') . ' id="lastname"') . (zen_not_null(ENTRY_LAST_NAME_TEXT) ? '<span class="alert">' ENTRY_LAST_NAME_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="street-address"><?php echo ENTRY_STREET_ADDRESS?></label>
      <?php echo zen_draw_input_field('street_address'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_street_address''40') . ' id="street-address"') . (zen_not_null(ENTRY_STREET_ADDRESS_TEXT) ? '<span class="alert">' ENTRY_STREET_ADDRESS_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <?php echo zen_draw_input_field('should_be_empty'''' size="40" id="CAAS" style="visibility:hidden; display:none;" autocomplete="off"'); ?>

    <?php
      
    if (ACCOUNT_SUBURB == 'true') {
    ?>
    <label class="inputLabel" for="suburb"><?php echo ENTRY_SUBURB?></label>
    <?php echo zen_draw_input_field('suburb'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_suburb''40') . ' id="suburb"') . (zen_not_null(ENTRY_SUBURB_TEXT) ? '<span class="alert">' ENTRY_SUBURB_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="city"><?php echo ENTRY_CITY?></label>
    <?php echo zen_draw_input_field('city'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_city''40') . ' id="city"') . (zen_not_null(ENTRY_CITY_TEXT) ? '<span class="alert">' ENTRY_CITY_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <?php
      
    if (ACCOUNT_STATE == 'true') {
        if (
    $flag_show_pulldown_states == true) {
    ?>
    <label class="inputLabel" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE?></label>
    <?php
          
    echo zen_draw_pull_down_menu('zone_id'zen_prepare_country_zones_pull_down($selected_country), $zone_id'id="stateZone"');
          if (
    zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' ENTRY_STATE_TEXT '</span>';
        }
    ?>

    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php ?>
    <label class="inputLabel" for="state" id="stateLabel"><?php echo $state_field_label?></label>
    <?php
        
    echo zen_draw_input_field('state'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_state''40') . ' id="state"');
        if (
    zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert" id="stText">' ENTRY_STATE_TEXT '</span>';
        if (
    $flag_show_pulldown_states == false) {
          echo 
    zen_draw_hidden_field('zone_id'$zone_name' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="postcode"><?php echo ENTRY_POST_CODE?></label>
    <?php echo zen_draw_input_field('postcode'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_postcode''40') . ' id="postcode"') . (zen_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="alert">' ENTRY_POST_CODE_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="country"><?php echo ENTRY_COUNTRY?></label>
    <?php echo zen_get_country_list('zone_country_id'$selected_country'id="country" ' . ($flag_show_pulldown_states == true 'onchange="update_zone(this.form);"' '')) . (zen_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="alert">' ENTRY_COUNTRY_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    </fieldset>
    Here are my alterations:

    PHP Code:
    <fieldset>
    <legend><?php echo TABLE_HEADING_ADDRESS_DETAILS?></legend>
    <?php
      
    if (ACCOUNT_GENDER == 'true') {
    ?>
    <?php 
    echo zen_draw_radio_field('gender''m''''id="gender-male"') . '<label class="radioButtonLabel" for="gender-male">' MALE '</label>' zen_draw_radio_field('gender''f''''id="gender-female"') . '<label class="radioButtonLabel" for="gender-female">' FEMALE '</label>' . (zen_not_null(ENTRY_GENDER_TEXT) ? '<span class="alert">' ENTRY_GENDER_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="firstname"><?php echo ENTRY_FIRST_NAME?></label>
    <?php echo zen_draw_input_field('firstname'''zen_set_field_length(TABLE_CUSTOMERS'customers_firstname''40') . ' id="firstname"') . (zen_not_null(ENTRY_FIRST_NAME_TEXT) ? '<span class="alert">' ENTRY_FIRST_NAME_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="lastname"><?php echo ENTRY_LAST_NAME?></label>
    <?php echo zen_draw_input_field('lastname'''zen_set_field_length(TABLE_CUSTOMERS'customers_lastname''40') . ' id="lastname"') . (zen_not_null(ENTRY_LAST_NAME_TEXT) ? '<span class="alert">' ENTRY_LAST_NAME_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="street-address"><?php echo ENTRY_STREET_ADDRESS?></label>
      <?php echo zen_draw_input_field('street_address'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_street_address''40') . ' id="street-address"') . (zen_not_null(ENTRY_STREET_ADDRESS_TEXT) ? '<span class="alert">' ENTRY_STREET_ADDRESS_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <?php echo zen_draw_input_field('should_be_empty'''' size="40" id="CAAS" style="visibility:hidden; display:none;" autocomplete="off"'); ?>

    <?php
      
    if (ACCOUNT_SUBURB == 'true') {
    ?>
    <label class="inputLabel" for="suburb"><?php echo ENTRY_SUBURB?></label>
    <?php echo zen_draw_input_field('suburb'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_suburb''40') . ' id="suburb"') . (zen_not_null(ENTRY_SUBURB_TEXT) ? '<span class="alert">' ENTRY_SUBURB_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="city"><?php echo ENTRY_CITY?></label>
    <?php echo zen_draw_input_field('city'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_city''40') . ' id="city"') . (zen_not_null(ENTRY_CITY_TEXT) ? '<span class="alert">' ENTRY_CITY_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="country"><?php echo ENTRY_COUNTRY?></label>
    <?php echo zen_get_country_list('zone_country_id'$selected_country'id="country" ' . ($flag_show_pulldown_states == true 'onchange="update_zone(this.form);"' '')) . (zen_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="alert">' ENTRY_COUNTRY_TEXT '</span>'''); ?>
    <br class="clearBoth" />

    <?php
      
    if (ACCOUNT_STATE == 'true') {
        if (
    $flag_show_pulldown_states == true) {
    ?>
    <label class="inputLabel" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE?></label>
    <?php
          
    echo zen_draw_pull_down_menu('zone_id'zen_prepare_country_zones_pull_down($selected_country), $zone_id'id="stateZone"');
          if (
    zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' ENTRY_STATE_TEXT '</span>';
        }
    ?>

    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php ?>
    <label class="inputLabel" for="state" id="stateLabel"><?php echo $state_field_label?></label>
    <?php
        
    echo zen_draw_input_field('state'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_state''40') . ' id="state"');
        if (
    zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert" id="stText">' ENTRY_STATE_TEXT '</span>';
        if (
    $flag_show_pulldown_states == false) {
          echo 
    zen_draw_hidden_field('zone_id'$zone_name' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      
    }
    ?>

    <label class="inputLabel" for="postcode"><?php echo ENTRY_POST_CODE?></label>
    <?php echo zen_draw_input_field('postcode'''zen_set_field_length(TABLE_ADDRESS_BOOK'entry_postcode''40') . ' id="postcode"') . (zen_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="alert">' ENTRY_POST_CODE_TEXT '</span>'''); ?>
    <br class="clearBoth" />
    </fieldset>

    See how I put the COUNTRY selector above the STATE selector.

    Make sure to set State Always as a Pulldown in your ZC admin.
    Last edited by schoolboy; 2 Apr 2013 at 01:22 PM.
    20 years a Zencart User

  4. #4
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,267
    Plugin Contributions
    3

    Default Re: Only display states selection box when from a certain country

    My technique DOES NOT "bypass" what Dr Byte says... You still need to define the states as he described.
    20 years a Zencart User

 

 

Similar Threads

  1. Replies: 7
    Last Post: 28 Dec 2011, 09:10 PM
  2. Special Item Shipping Charges Only within Certain States?
    By DCDC in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 19 Dec 2009, 06:51 AM
  3. Flat rate or similar module to only display when over a certain weight?
    By sam_m in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 3 Dec 2008, 12:36 AM
  4. only display new products from certain categories?
    By hawkeye in forum General Questions
    Replies: 1
    Last Post: 15 May 2007, 05:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg