joe123 Posted April 1, 2008 Share Posted April 1, 2008 Script to Auto Detect Your website visitors Country and automatically select it and auto select the selected country's states/regions. 1. download the ip to country database From http://ip-to-country.webhosting.info/node/view/6 2. Create a table in your whmcs database called "tbliptocountry" with 5 Fields ip_from ip_to country_code2 country_code3 country 3.import the database(ip-to-country.csv) into tbliptocountry. I included a file called test.php ,upload it to your whmcs directory and call it in your browser if your country code is showing correct then the database is ready to be used the file that should be used with the script is iptoc.php. Included are 2 versions of the script 1. the following files are to auto detect the visitors country and populates the states. (included are 4 files , clientregister.tpl , countrystate.js , iptoc.php , test.php ) http://www.hosting777.com/countrystate1.zip 2.the following is just the countries and states without country detect.( countrystate.js , clientregister.tpl ) http://www.hosting777.com/countrystate2.zip Look at the changes made in clientregister.tpl and change it accordingly in your order-signup.tpl file. currently only the states for the following countries are included if you add more , don't forget to share. United States Canada Australia Austria Brazil Spain Netherlands United Kingdom Ireland Belgium Germany Denmark France Try the demo here ->> http://www.hosting777.com/clients/register.php Enjoy it ! 0 Quote Link to comment Share on other sites More sharing options...
indtg Posted April 1, 2008 Share Posted April 1, 2008 Very nice joe123! Can you add any type of error handling in case you are not able to get a proper ip to country match? Just for kicks, I tried your demo with proxify.com (remove all scripts unchecked) and both the state/region and country fields were blank. It works if you don't use an anonymous proxy though. I think this is just a result of there not being an ip to country match for whichever IP address proxify.com was using at the time. Looks and works great though. 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 If you don't surf with proxy and there is no IP match , it will default to the United States , and i do NOT want any visitor to register through anonymous Proxy anyway. 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted April 1, 2008 Share Posted April 1, 2008 Hey Joe, For registration page there is no problems. Dropdown countries and states flieds run ok (img1), but if a customer place an order is different (img2). It doesn't appears dropdown fields. I've made some changes in order-signup.tpl file taking clientregister.tpl file like model without any success. I use "portal" templates and "boxes" orderforms. May you explain me what I must to do? One more thing; I've no root access on my server. I can create a new table called "tbliptocountry" with 5 fields, but I don't know the values to insert in varchar, primary key, null, etc.etc. I'm waiting for your reply Joe. Thank you 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 I forgot , Put the following hidden Fields after the Opening <form> tag <input type="hidden" value="countrySelect" name="clientcountry" id="clientcountry"> <input type="hidden" value="stateSelect" name="clientstate" id="clientstate" /> <input type="hidden" value="countrydefault" name="clientcountry_default" id="clientcountry_default" /> <input type="hidden" value="statedefault" name="clientstate_default" id="clientstate_default" /> <input type="hidden" value="US" name="countrydefault" id="countrydefault"> <input type="hidden" value="" name="statedefault" id="statedefault"> I will make a Video soon how to create the table and the fields exactly . will post it in about 30 Minutes . 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted April 1, 2008 Share Posted April 1, 2008 I did it. And nothing. 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 I did it. And nothing. What files are you Using ?, Because the code in javascript and the clientregister.tpl in the both versions is different. 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted April 1, 2008 Share Posted April 1, 2008 This is /portal/clientregister.tpl code I use {if $noregistration} Not Allowed {else} <p>{$LANG.clientregisterheadertext}</p> {if $errormessage}<div class="errorbox">{$errormessage|replace:'<li>':' # '} # </div><br />{/if} <form method="post" action="{$SERVER.PHP_SELF}"> <input type="hidden" name="register" value="true" /> <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="ES" 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> {* CHANGE START *} <SCRIPT type="text/javascript" SRC="http://www.mydomain.com/clients/templates/portal/countrystate.js"></SCRIPT> <tr><td class="fieldarea">{$LANG.clientareastate}</td><td><span><select id='stateSelect' name='state'></select></span> *</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> {* CHANGE END *} <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><strong> » {$LANG.orderlogininfo}</strong></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 $capatacha} <p><strong> » {$LANG.clientregisterverify}</strong></p> <p>{$LANG.clientregisterverifydescription}</p> <p align="center"><img src="includes/verifyimage.php" align="middle"> <input type="text" name="code" size="10" maxlength="5"> </p> {/if} {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> {/if} And this is for templates/orderforms/boxes/order-signup.tpl <p>{$LANG.orderprogress}: {$LANG.orderchooseapackage} > {$LANG.orderdomainoptions} > {$LANG.orderconfigure} > {$LANG.orderconfirmorder} > <strong>{$LANG.ordercheckout}</strong></p> {if $errormessage}<div class="errorbox">{$errormessage|replace:'<li>':' # '} # </div><br />{/if} <form method="post" action="{$SERVER.PHP_SELF}"> <input type="hidden" name="register" value="true" /> <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="ES" 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> {* CHANGE START *} <SCRIPT type="text/javascript" SRC="http://www.mydomain.com/clients/templates/portal/countrystate.js"></SCRIPT> <tr><td class="fieldarea">{$LANG.clientareastate}</td><td><span><select id='stateSelect' name='state'></select></span> *</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> {* CHANGE END *} <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> 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 From the image above i see you are using the cart so you have to edit viewcart.tpl I guess ( i dont use it) and the other form is working fine http://www.sudomyhost.com/clients/register.php and dont forget that sometimes you have to delete the files in templates_c to see the changes and refreshing the page as well. 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted April 1, 2008 Share Posted April 1, 2008 From the image above i see you are using the cart so you have to edit viewcart.tpl I guess ( i dont use it)and the other form is working fine http://www.sudomyhost.com/clients/register.php and dont forget that sometimes you have to delete the files in templates_c to see the changes and refreshing the page as well. Hey Joe, Something I've made wrong on viewcart.tpl file code. It dosn't calculate tax an goes directly to create the account. May you do it for me, please? In the attach is the viewcart.tpl code Thank you viewcart.txt 0 Quote Link to comment Share on other sites More sharing options...
Nick Posted April 1, 2008 Share Posted April 1, 2008 You've only got English regions/counties listed in the drop down box when UK is selected. 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 try the attached file , my system does not apply tax with the normal files as well so i cant really check it, looks like i need to update some files in my installation. viewcart.zip 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted April 1, 2008 Author Share Posted April 1, 2008 You've only got English regions/counties listed in the drop down box when UK is selected. Add the rest and post them here ! 0 Quote Link to comment Share on other sites More sharing options...
LemonBarley Posted October 14, 2008 Share Posted October 14, 2008 (edited) i checked joe123's viewcart. its not working. The states will not show. Only country is being selected. even in this host, its not working http://www.sudomyhost.com/clients/cart.php?a=checkout something si really wrong with viewcart.tpl. maybe joe123 can give it a check. Edited October 14, 2008 by LemonBarley 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted October 15, 2008 Author Share Posted October 15, 2008 i checked joe123's viewcart. its not working. The states will not show. Only country is being selected. even in this host, its not working http://www.sudomyhost.com/clients/cart.php?a=checkout something si really wrong with viewcart.tpl. maybe joe123 can give it a check. Sorry , but i have been kidnapped by aliens and they promised they will release me at the coming weekend , i will look at it then ! 0 Quote Link to comment Share on other sites More sharing options...
joe123 Posted October 16, 2008 Author Share Posted October 16, 2008 here is the viewcart.tpl and working http://www.hosting777.com/clients/cart.php this is for the cart orderform ! viewcart.zip 0 Quote Link to comment Share on other sites More sharing options...
Berenguer IV Posted October 16, 2008 Share Posted October 16, 2008 For me it works all right. See the image attached. Thank you a lot Joe. Great job !! 0 Quote Link to comment Share on other sites More sharing options...
Business Hosting Online Posted June 19, 2009 Share Posted June 19, 2009 Will this work with version 4+ or is it already implemented? 0 Quote Link to comment Share on other sites More sharing options...
spaceman Posted June 19, 2009 Share Posted June 19, 2009 yes for me works perfect. thanks 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted September 10, 2009 Share Posted September 10, 2009 Hello, Joe123, I see this thread is pretty old. Can I follow instructions on the first post on a 4.0+ installation ? Thanks, great contrib. 0 Quote Link to comment Share on other sites More sharing options...
meneketehe Posted September 11, 2009 Share Posted September 11, 2009 Hello, Joe123, I see this thread is pretty old. Can I follow instructions on the first post on a 4.0+ installation ? Thanks, great contrib. it'll work on v.4 you might also apply 'em to clientareadetails.tpl, clientareacontacts.tpl, clientareaaddcontact.tpl 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted September 11, 2009 Share Posted September 11, 2009 nice, I'll wait for the new release! 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.