Jump to content

State Drop-Down List in Order Form!


Recommended Posts

How do I set a form value to that of a smarty value. For example,

there is a smarty variable ($state="TX"), but the form <input

type=select name=state> does not maintain the form state. How can I

set the form value state to the smarty $state value? e.g.

form.state.value=$state. The problem is, each time I go back to orders-stepthree.tpl the state is not maintained.

 

Or, can I create an array inside the template because the .php file

is ioncube encoded, e.g.:

 

{html_options name=state selected=$state values=[1,2,3] output=[one,two,three]}

 

My only other painful option is:

 

<select name=state>

<option value="TX" {if $state eq "TX"} selected {/if}>Texas</option>

<option value="CA" {if $state eq "CA"} selected {/if}>California</option>

....

 

Thanks,

Brad

Link to comment
Share on other sites

<table>

{if $taxstatecheck}<tr><td width=100>{$LANG.clientareastate}</td><td>

{php}

$state_list = array('AL'=>"Alabama",

'AK'=>"Alaska",

'AZ'=>"Arizona",

'AR'=>"Arkansas",

'CA'=>"California",

'CO'=>"Colorado",

'CT'=>"Connecticut",

'DE'=>"Delaware",

'DC'=>"District Of Columbia",

'FL'=>"Florida",

'GA'=>"Georgia",

'HI'=>"Hawaii",

'ID'=>"Idaho",

'IL'=>"Illinois",

'IN'=>"Indiana",

'IA'=>"Iowa",

'KS'=>"Kansas",

'KY'=>"Kentucky",

'LA'=>"Louisiana",

'ME'=>"Maine",

'MD'=>"Maryland",

'MA'=>"Massachusetts",

'MI'=>"Michigan",

'MN'=>"Minnesota",

'MS'=>"Mississippi",

'MO'=>"Missouri",

'MT'=>"Montana",

'NE'=>"Nebraska",

'NV'=>"Nevada",

'NH'=>"New Hampshire",

'NJ'=>"New Jersey",

'NM'=>"New Mexico",

'NY'=>"New York",

'NC'=>"North Carolina",

'ND'=>"North Dakota",

'OH'=>"Ohio",

'OK'=>"Oklahoma",

'OR'=>"Oregon",

'PA'=>"Pennsylvania",

'RI'=>"Rhode Island",

'SC'=>"South Carolina",

'SD'=>"South Dakota",

'TN'=>"Tennessee",

'TX'=>"Texas",

'UT'=>"Utah",

'VT'=>"Vermont",

'VA'=>"Virginia",

'WA'=>"Washington",

'WV'=>"West Virginia",

'WI'=>"Wisconsin",

'WY'=>"Wyoming");

$this->assign('states',$state_list);

{/php}

{html_options name=state options=$states selected=$state}

</td>

</tr>{/if}

{if $taxcountrycheck}<tr><td>{$LANG.clientareacountry}</td><td>{$clientcountriesdropdown}</td></tr>{/if}

</table>

Link to comment
Share on other sites

  • 4 weeks later...

here is my code for the state dropdown - it uses the long select format:

 

<select name="state" value="{$clientstate}">
                   <option value="Select a State" {if $clientstate eq ""} selected {/if}>Select a State</option>
                   <option value="AL" {if $clientstate eq "AL"} selected {/if}>Alabama </option>
                   <option value="AK" {if $clientstate eq "AK"} selected {/if}>Alaska </option>
                   <option value="AZ" {if $clientstate eq "AZ"} selected {/if}>Arizona </option>
                   <option value="AR" {if $clientstate eq "AR"} selected {/if}>Arkansas </option>
                   <option value="CA" {if $clientstate eq "CA"} selected {/if}>California </option>
                   <option value="CO" {if $clientstate eq "CO"} selected {/if}>Colorado </option>
                   <option value="CT" {if $clientstate eq "CT"} selected {/if}>Connecticut </option>
                   <option value="DE" {if $clientstate eq "DE"} selected {/if}>Delaware </option>
                   <option value="DC" {if $clientstate eq "DC"} selected {/if}>District Of Columbia </option>
                   <option value="FL" {if $clientstate eq "FL"} selected {/if}>Florida </option>
                   <option value="GA" {if $clientstate eq "GA"} selected {/if}>Georgia </option>
                   <option value="HI" {if $clientstate eq "HI"} selected {/if}>Hawaii </option>
                   <option value="ID" {if $clientstate eq "ID"} selected {/if}>Idaho </option>
				<option value="IL" {if $clientstate eq "IL"} selected {/if}>Illinois </option>
                   <option value="IN" {if $clientstate eq "IN"} selected {/if}>Indiana </option>
                   <option value="IA" {if $clientstate eq "IA"} selected {/if}>Iowa </option>
                   <option value="KS" {if $clientstate eq "KS"} selected {/if}>Kansas </option>
                   <option value="KY" {if $clientstate eq "KY"} selected {/if}>Kentucky </option>
                   <option value="LA" {if $clientstate eq "LA"} selected {/if}>Louisiana </option>
                   <option value="ME" {if $clientstate eq "ME"} selected {/if}>Maine </option>
                   <option value="MD" {if $clientstate eq "MD"} selected {/if}>Maryland </option>
                   <option value="MA" {if $clientstate eq "MA"} selected {/if}>Massachusetts </option>
                   <option value="MI" {if $clientstate eq "MI"} selected {/if}>Michigan </option>
                   <option value="MN" {if $clientstate eq "MN"} selected {/if}>Minnesota </option>
                   <option value="MS" {if $clientstate eq "MS"} selected {/if}>Mississippi </option>
                   <option value="MO" {if $clientstate eq "MO"} selected {/if}>Missouri </option>
                   <option value="MT" {if $clientstate eq "MT"} selected {/if}>Montana </option>
                   <option value="NE" {if $clientstate eq "NE"} selected {/if}>Nebraska </option>
                   <option value="NV" {if $clientstate eq "NV"} selected {/if}>Nevada </option>
                   <option value="NH" {if $clientstate eq "NH"} selected {/if}>New Hampshire </option>
                   <option value="NJ" {if $clientstate eq "NJ"} selected {/if}>New Jersey </option>
                   <option value="NM" {if $clientstate eq "NM"} selected {/if}>New Mexico </option>
				<option value="NY" {if $clientstate eq "NY"} selected {/if}>New York </option>
				<option value="NC" {if $clientstate eq "NC"} selected {/if}>North Carolina </option>
                   <option value="ND" {if $clientstate eq "ND"} selected {/if}>North Dakota </option>			
                   <option value="OH" {if $clientstate eq "OH"} selected {/if}>Ohio </option>
                   <option value="OK" {if $clientstate eq "OK"} selected {/if}>Oklahoma </option>
                   <option value="OR" {if $clientstate eq "OR"} selected {/if}>Oregon </option>
                   <option value="PA" {if $clientstate eq "PA"} selected {/if}>Pennsylvania </option>
                   <option value="RI" {if $clientstate eq "RI"} selected {/if}>Rhode Island </option>
                   <option value="SC" {if $clientstate eq "SC"} selected {/if}>South Carolina </option>
                   <option value="SD" {if $clientstate eq "SD"} selected {/if}>South Dakota </option>
                   <option value="TN" {if $clientstate eq "TN"} selected {/if}>Tennessee </option>
                   <option value="TX" {if $clientstate eq "TX"} selected {/if}>Texas </option>
                   <option value="UT" {if $clientstate eq "UT"} selected {/if}>Utah </option>
                   <option value="VT" {if $clientstate eq "VT"} selected {/if}>Vermont </option>
                   <option value="VA" {if $clientstate eq "VA"} selected {/if}>Virginia </option>
                   <option value="WA" {if $clientstate eq "WA"} selected {/if}>Washington </option>
                   <option value="WV" {if $clientstate eq "WV"} selected {/if}>West Virginia </option>
                   <option value="WI" {if $clientstate eq "WI"} selected {/if}>Wisconsin </option>
                   <option value="WY" {if $clientstate eq "WY"} selected {/if}>Wyoming </option>
                 </select> *

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
Should be easy to do with a IF statement - for example - If country = US show the state list box. else - do the other.

 

That makes sense. I've seen many where they've pretty much got every region of most countries, though that would be more work than it's worth.

Link to comment
Share on other sites

  • 2 weeks later...
Should be easy to do with a IF statement - for example - If country = US show the state list box. else - do the other.

 

That makes sense. I've seen many where they've pretty much got every region of most countries, though that would be more work than it's worth.

 

I think you can do this with AJAX - have seen it done with ecommerce carts and countries.

 

Sorry - am not a coder so cannot help any further. Just thought I would mention it though in case someone who understands AJAX coding can produce what you need

Link to comment
Share on other sites

  • 9 months later...

just thought I'd make it easy for all those downunder.

 

below is the same code, changed to suit Australian states only

 

<select name="state" value="{$clientstate}">

<option value="Select a State" {if $clientstate eq ""} selected {/if}>Select a State</option>

<option value="ACT" {if $clientstate eq "ACT"} selected {/if}>Australian Capital Territory</option>

<option value="NSW" {if $clientstate eq "NSW"} selected {/if}>New South Wales</option>

<option value="NT" {if $clientstate eq "NT"} selected {/if}>Northern Territory</option>

<option value="QLD" {if $clientstate eq "QLD"} selected {/if}>Queensland</option>

<option value="SA" {if $clientstate eq "SA"} selected {/if}>South Australia</option>

<option value="TAS" {if $clientstate eq "TAS"} selected {/if}>Tasmania</option>

<option value="VIC" {if $clientstate eq "VIC"} selected {/if}>Victoria</option>

<option value="WA" {if $clientstate eq "WA"} selected {/if}>Western Australia</option>

<option value="OTH" {if $clientstate eq "Oth"} selected {/if}>Outside of Australia</option>

</select>

I've found that you have to add it to the following files in whichever templates you are using (portal/default/custom etc)

- clientareadetails.tpl

- clientareacontacts.tpl

- clientareaaddcontact.tpl

- clientregister.tpl

 

 

there may also be other files in the portal template that you have to modify.

 

Always remember,backup first, "Caveat Emptor" and test, test test.

Link to comment
Share on other sites

I just finished implemnting this feature and would like you to test it if possible.

Now the only problem where do i get an easy list of countries with there states (don´t send me to wikipedia :) i just need an easy list that easy to copy.

 

This script is realy nice when you change a country it refreshes the states without you noticing it , it does that without refreshing the page .

the only countries that has states at the moment are , United States , Canada , United Kingdom and Austria and if a country does not have a state , it will just change to a normal Input Field .

Please test it and let me know if there are any errors or problems .

 

http://www.hosting777.com/clients/register.php

 

Thanks

Link to comment
Share on other sites

I just finished implemnting this feature and would like you to test it if possible.

Now the only problem where do i get an easy list of countries with there states (don´t send me to wikipedia :) i just need an easy list that easy to copy.

 

This script is realy nice when you change a country it refreshes the states without you noticing it , it does that without refreshing the page .

the only countries that has states at the moment are , United States , Canada , United Kingdom and Austria and if a country does not have a state , it will just change to a normal Input Field .

Please test it and let me know if there are any errors or problems .

 

http://www.hosting777.com/clients/register.php

 

Thanks

 

Sorry Joe123,

 

Attached file has now the spanish states list ready to copy and paste.

spanish_states_final.txt

Link to comment
Share on other sites

I just finished implemnting this feature and would like you to test it if possible.

Now the only problem where do i get an easy list of countries with there states (don´t send me to wikipedia :) i just need an easy list that easy to copy.

 

This script is realy nice when you change a country it refreshes the states without you noticing it , it does that without refreshing the page .

the only countries that has states at the moment are , United States , Canada , United Kingdom and Austria and if a country does not have a state , it will just change to a normal Input Field .

Please test it and let me know if there are any errors or problems .

 

http://www.hosting777.com/clients/register.php

 

Thanks

 

Great job. though, United Kingdom includes Northern Ireland and so you need to add the following to the UK list.

 

Co. Antrim

Co. Armagh

Co. Down

Co. Fermanagh

Co. Londonderry

Co. Tyrone

 

Also, I'm a little confused as to why you have both Great Britain and United Kingdom. Drop the Great Britain as most sites have United Kingdom only.

 

Si

Link to comment
Share on other sites

OK guys here is the latest on this

I have been testing a script that i found on the net and looks much more advanced than the one i was going to give you but it works the same .

 

you can download it here:

http://www.hosting777.com/countrystate.zip

 

the script will work fine with whmcs and your form in order-signup.tpl (singlepage orderform) or clientregister.tpl (portal) should look like this in order for it to work.

 

 
<form method="post" action="{$smarty.server.PHP_SELF}?step=6">
<input type="hidden" value="countrySelect" name="clientcountry" id="clientcountry">
<input type="hidden" value="stateSelect"   name="clientstate"   id="clientstate" />
<!-- The id of the the fields holding the default values.  If more than one, seperate with spaces -->
<input type="hidden" value="countrydefault" name="clientcountry_default" id="clientcountry_default" />
<input type="hidden" value="statedefault"   name="clientstate_default"   id="clientstate_default" />
<!-- The actual default values -->
<input type="hidden" value="US" name="countrydefault" id="countrydefault">
<input type="hidden" value=""   name="statedefault"   id="statedefault">
<table cellspacing="1" cellpadding="0" class="frame"><tr><td>
<table width="100%" cellpadding="2">
<tr><td width="150" class="fieldarea">{$LANG.clientareafirstname}</td><td><input type="text" name="firstname" size="30" value="{$clientfirstname}" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientarealastname}</td><td><input type="text" name="lastname" size="30" value="{$clientlastname}" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareacompanyname}</td><td><input type="text" name="companyname" size="30" value="{$clientcompanyname}" /></td></tr>
<tr><td class="fieldarea">{$LANG.clientareaemail}</td><td><input type="text" name="email" size="50" value="{$clientemail}" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareaaddress1}</td><td><input type="text" name="address1" size="40" value="{$clientaddress1}" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareaaddress2}</td><td><input type="text" name="address2" size="30" value="{$clientaddress2}" /></td></tr>
<tr><td class="fieldarea">{$LANG.clientareacity}</td><td><input type="text" name="city" size="30" value="{$clientcity}" /> *</td></tr>
<SCRIPT type="text/javascript" SRC="path/to/countrystate.js"></SCRIPT>
<tr><td class="fieldarea">{$LANG.clientareastate}</td><td><select id='stateSelect' name='state'>
  </select> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareapostcode}</td><td><input type="text" name="postcode" size="10" value="{$clientpostcode}" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareacountry}</td><td><div>
     <select id='countrySelect' name='country' onchange='updateState(this.id)'>
     </select>
*</div>
<SCRIPT  type="text/javascript">initCountry(); </SCRIPT> </td></tr>
<tr><td class="fieldarea">{$LANG.clientareaphonenumber}</td><td><input type="text" name="phonenumber" size="20" value="{$clientphonenumber}" /> *</td></tr>
{if $customfields}<tr><td class="fieldarea"><br></td></tr>{/if}
{foreach key=num item=customfield from=$customfields}
<tr><td class="fieldarea">{$customfield.name}</td><td>{$customfield.input} {$customfield.required}</td></tr>
{/foreach}
</table>
</td></tr></table>
<p><b> » {$LANG.orderlogininfo}</b></p>
<p>{$LANG.orderlogininfopart1} {$companyname} {$LANG.orderlogininfopart2}</p>
<table cellspacing="1" cellpadding="0" class="frame"><tr><td>
<table width="100%" cellpadding="2">
<tr><td width="150" class="fieldarea">{$LANG.clientareapassword}</td><td><input type="password" name="password" size="30" /> *</td></tr>
<tr><td class="fieldarea">{$LANG.clientareaconfirmpassword}</td><td><input type="password" name="password2" size="30" /> *</td></tr>
</table>
</td></tr></table>
{if $accepttos}
<p><input type="checkbox" name="accepttos" id="accepttos" /> <label for="accepttos">{$LANG.ordertosagreement} <a href="{$tosurl}" target="_blank">{$LANG.ordertos}</a></label>.<p>
{/if}
<p align="center"><input type="submit" value="{$LANG.ordercontinuebutton}" /></p>
</form>

 

I ulpoaded a list of the missing states and located at http://www.hosting777.com/states.txt

 

Look at the script How to add them and when you are done to add them post them here that all others who want to use the script can add them as well .

 

Enjoy

Link to comment
Share on other sites

the only countries that has states at the moment are , United States , Canada , United Kingdom and Austria and if a country does not have a state ,

 

Thanks

 

Nice implementattion, have yet to test on a cart setup, but will implement shortly.

2 points

1. The Australian states are duplicating on your site, and

2. (not to do with the code) us "Austrians" get pretty upset with being confused with a bunch of yodlers (which also means something completely different downunder) ;)

 

Cheers

Link to comment
Share on other sites

(not to do with the code) us "Austrians" get pretty upset with being confused with a bunch of yodlers (which also means something completely different downunder)

 

Right , tourists going to Austria want to see kangaroos and in Australia they want to watch the SängerKnaben :)

Link to comment
Share on other sites

Hey Joe123,

 

in countrystate.js file (line 619)

 

selObj.options[0] = new Option('Select State','');

 

This is for all countries.

 

In Spanish (option ES) will be better something like this:

selObj.options[0] = new Option('Seleccione la Provincia','');

 

May you do it, please?

 

Thank you Joe, great job.

 

In Spain there are some states (provincias) like Ceuta, Melilla, Sta. Cruz de Tenerife and Las Palmas de G.C. that they have duty free. No tax. The rest 16 %.

On WHMCS original script, people from Sta. Cruz de Tenerife, for exemple, on registration can write Santa Cruz de Tenerife (this is the whole name and it is correct).

Well, on WHMCS Admin Panel if I have configurated special Tax for St. Cruz de Tenerife state and people write the whole name on checkout or registration ......... later the tax aplication for this customer fails.

 

With your job dosn't, because it forces to people selecting the state with the name like you want to appears.

Fantastic !

Link to comment
Share on other sites

Thanks Joe.

Now My Site is only in spanish, but my idea is put it in all languages in a short time.

Anyway, I've solutioned typing "Selec ...". That is ok.

 

One thing more;

If you select a country (f.e., Uganda) then the mandatory asterisc appears on left of ehe field. If you want to return to United States, still on left too.

It is a simply detail, but if you fix it, would be better.

Link to comment
Share on other sites

One thing more;

If you select a country (f.e., Uganda) then the mandatory asterisc appears on left of ehe field. If you want to return to United States, still on left too.

It is a simply detail, but if you fix it, would be better

.

 

change your code to :

<tr><td class="fieldarea">{$LANG.clientareastate}</td><td><span><select id='stateSelect' name='state'></select></span> *</td></tr>

Link to comment
Share on other sites

Thanks Joe for this contribution. Just one question -- on the line which defines the location of countrystate.js, what directory is that relative to? I've put the js file in the same directory as order-signup.tpl, but when I get to the signup page the country and state field dropdowns are empty. This is what I coded:

 

<SCRIPT type="text/javascript" SRC="templates/orderforms/singlepage/countrystate.js"></SCRIPT>

Link to comment
Share on other sites

if the script is in the same place as the .tpl files you can use :

 

<SCRIPT type="text/javascript" SRC="/whmcs/templates/orderforms/singlepage/countrystate.js"></SCRIPT>

Don't forget the slash at the begining of the path or use just :

 

<SCRIPT type="text/javascript" SRC="../countrystate.js"></SCRIPT>

 

Both will do

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated