bradandersen Posted April 7, 2007 Share Posted April 7, 2007 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 0 Quote Link to comment Share on other sites More sharing options...
bradandersen Posted April 7, 2007 Author Share Posted April 7, 2007 <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> 0 Quote Link to comment Share on other sites More sharing options...
generic Posted May 4, 2007 Share Posted May 4, 2007 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> * 0 Quote Link to comment Share on other sites More sharing options...
skshost Posted May 20, 2007 Share Posted May 20, 2007 This pretty much limits your customers to US residents only. It would be a lot of work, but I'd like to see something that changes the State/Region dropdown options when the country is selected. 0 Quote Link to comment Share on other sites More sharing options...
jerett Posted May 24, 2007 Share Posted May 24, 2007 Should be easy to do with a IF statement - for example - If country = US show the state list box. else - do the other. 0 Quote Link to comment Share on other sites More sharing options...
skshost Posted June 2, 2007 Share Posted June 2, 2007 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. 0 Quote Link to comment Share on other sites More sharing options...
dataferret Posted June 14, 2007 Share Posted June 14, 2007 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 0 Quote Link to comment Share on other sites More sharing options...
Zorro67 Posted March 20, 2008 Share Posted March 20, 2008 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. 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 26, 2008 Share Posted March 26, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted March 27, 2008 Share Posted March 27, 2008 Hey Joe123, great job ! In the attached file there are all spanish current states. May you inserted in you project and share it? spanish_states.txt 0 Quote Link to comment Share on other sites More sharing options...
zigzam Posted March 27, 2008 Share Posted March 27, 2008 This is great. It should be included with the default whmcs install. 0 Quote Link to comment Share on other sites More sharing options...
nielsenj Posted March 27, 2008 Share Posted March 27, 2008 http://www.hosting777.com/clients/register.php Thanks Nice job joe! I'm hoping you release it! I was working on something similar to go along with an AJAX email validation. 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted March 27, 2008 Share Posted March 27, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 27, 2008 Share Posted March 27, 2008 Thank you Berenguer IV for the spanish list , i have now a complete list to add , it will take sometime to add all of those states manually but when its done sure i will release it ! 0 Quote Link to comment Share on other sites More sharing options...
Si Posted March 27, 2008 Share Posted March 27, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 28, 2008 Share Posted March 28, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
Zorro67 Posted March 28, 2008 Share Posted March 28, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 28, 2008 Share Posted March 28, 2008 (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 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted March 28, 2008 Share Posted March 28, 2008 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 ! 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 28, 2008 Share Posted March 28, 2008 Berenguer IV If your Site is in Spanish then you can change it in lines 619 , 652 To whatever you like. after removing the Australian double entry , they are now on lines 612 645. 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted March 28, 2008 Share Posted March 28, 2008 Thank you Berenguer IV for the spanish list , i have now a complete list to add , it will take sometime to add all of those states manually but when its done sure i will release it ! Look Joe, Attached file contents the whole spanish states (provincias) just for copy and paste in countrystate.js file. spanish_states_for_jsfile.txt 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted March 28, 2008 Share Posted March 28, 2008 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. 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 28, 2008 Share Posted March 28, 2008 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> 0 Quote Link to comment Share on other sites More sharing options...
apollo1 Posted March 28, 2008 Share Posted March 28, 2008 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> 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted March 28, 2008 Share Posted March 28, 2008 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 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.