Force State/Province dropdown to show relevant options for selected COUNTRY
If you use the State/Province DROPDOWN for your customer address-capture forms, you will notice that, as the input field for STATE/PROVINCE appears ABOVE the input field for COUNTRY, the options for STATE/PROVINCE will be those of the default COUNTRY.
This can be annoying for non-default country customers, who will try to see their STATE/PROVINCE in the dropdown, and won't!
It will appear only AFTER they choose their country (if, of course these zones are configured.)
If you put the input field for COUNTRY, above the input field for STATE/PROVINCE, then they select their COUNTRY first.
This will then populate the STATE/PROVINCE dropdown with appropriate names - or indicate a manual input...
There are TWO files to change:
tpl_modules_address_book_details.php
and
tpl_modules_create_account.php
Find these two bits of code:
This one for STATE/PROVINCE
PHP Code:
<?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 ' <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 ' <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
}
?>
This one for COUNTRY
PHP Code:
<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" />
Then make sure you move the COUNTRY section to above the STATE/PROVINCE section... like this:
PHP Code:
<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 ' <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 ' <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
}
?>
SAVE RESULTANT PHP FILES IN YOUR CUSTOM OR OVER-RIDES FOLDER
Re: Force State/Province dropdown to show relevant options for selected COUNTRY
Hi schoolboy,
You've misbehaved! Go stand in the corner. :smartass:
On my 1.3.7 test system, this modification drops the State/Province drop-down and field as well as the Post/Zip Code fields down below (outside of) the Address Details box (on the create account page page, at least).
I don't understand PHP well enough to fiddle it to get them back into the box. I'll bet you can though.
Rob
Re: Force State/Province dropdown to show relevant options for selected COUNTRY
OOps...
Perhaps the final
shouldn't be included...
The edit works for me...
www.commotionstore.co.uk (go to login)
-----------------------------------------------------------
I'll have a look at the code in my actual files... then re-post.
Re: Force State/Province dropdown to show relevant options for selected COUNTRY
Hi,
I'm sure it's something like that, but despite literally a decade of programming in scripting languages, PHP remains Greek to me -- and I ain't Greek! I wish I had time to study it, but not right now.
By the way, that's a great site. I see we share a desire to simplify, simplify! And great products too.
Rob
Re: Force State/Province dropdown to show relevant options for selected COUNTRY
i can show stateZone in admin/invoice.php ?