Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Register form post code validation script & possible password script

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-23-2009, 06:07 AM
 
Jeremy Smith Jeremy Smith is offline
 

Senior Member
  
Join Date: Jan 2009
Posts: 167
 

Question Register form post code validation script & possible password script

I've got another problem.

I have been asked to do some form validation on our site but the script I am using just refuses to work.

What I have done is, put the following javascript code into '/customer/home.tpl'

HTML Code:
{literal} <SCRIPT LANGUAGE="JavaScript"> function postit() { //check postcode format is valid test = document.registerform.b_zipcode.value; size = test.length test = test.toUpperCase(); //Change to uppercase while (test.slice(0,1) == " ") //Strip leading spaces {test = test.substr(1,size-1);size = test.length } while(test.slice(size-1,size)== " ") //Strip trailing spaces {test = test.substr(0,size-1);size = test.length } document.registerform.b_zipcode.value = test; //write back to form field if (size < 6 || size > 8){ //Code length rule alert(test + " is not a valid postcode - wrong length"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule alert(test + " is not a valid postcode - cannot start with a number"); document.registerform.b_zipcode.focus(); return false; } if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule alert(test + " is not a valid postcode - alpha character in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule alert(test + " is not a valid postcode - number in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule alert(test + " is not a valid postcode - number in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(test.charAt(size-4) == " ")){//space in position length-3 rule alert(test + " is not a valid postcode - no space or space in wrong position"); document.registerform.b_zipcode.focus(); return false; } count1 = test.indexOf(" ");count2 = test.lastIndexOf(" "); if (count1 != count2){//only one space rule alert(test + " is not a valid postcode - only one space allowed"); document.registerform.b_zipcode.focus(); return false; } alert("Postcode Format OK"); return true; } </script> {/literal}

I have as you can see I have changed the form object model variables to co align with the form.

I then added this in on the actual register form for customers '/customer/main/register.tpl ':

HTML Code:
{if $js_enabled and $usertype eq "C"} {include file="buttons/submit.tpl" type="input" style="button" href="javascript: return check_registerform_fields() + postit(); return false;"} {else} <input type="submit" value=" {$lng.lbl_submit|strip_tags:false|escape} " /> {/if}

But it keeps coming up with this error in FF v3:
Error: missing } in XML expression
Source File: http://mydomain.com/register.php?
Line: 24, Column: 1
Source Code:
test = test.toUpperCase(); //Change to uppercase

It works in normal html as such, with the following criteria for a successfull postcode validation script:
  1. The total length must be 6,7, or 8 characters, a gap (space character) must be included
  2. The inward code, the part to the right of the gap, must always be 3 characters
  3. The first character of the inward code must be numeric
  4. The second and third characters of the inward code must be alpha
  5. The outward code, the part to the left of the gap, can be 2,3, or 4 characters
  6. The first character of the outward code must be alpha
Can someone help please?

Thanks ever so much,
Jeremy.
__________________
Version 4.1.11 on Linux (Fedora)
X-Cart Gold
Reply With Quote
  #2  
Old 04-23-2009, 08:33 AM
 
Jeremy Smith Jeremy Smith is offline
 

Senior Member
  
Join Date: Jan 2009
Posts: 167
 

Question Re: Register form post code validation script & possible password script

Its working sort of.

The alerts working when you go into put a deliberate incorrect format postcode like purely JH but its still allowing it through, here's the 2 tpl files I have used to make it work kind of:

File: /customer/home.tpl

HTML Code:
<!-- POST CODE VALIDATION SCRIPT! --> {literal} <SCRIPT LANGUAGE="JavaScript"> function postit(){ //check postcode format is valid test = document.registerform.b_zipcode.value; size = test.length; test = test.toUpperCase(); //Change to uppercase while (test.slice(0,1) == " ") //Strip leading spaces {test = test.substr(1,size-1);size = test.length; } while (test.slice(size-1,size)== " ") //Strip trailing spaces {test = test.substr(0,size-1);size = test.length; } document.registerform.b_zipcode.value = test; //write back to form field if (size < 6 || size > 8){ //Code length rule alert(test + " is not a valid postcode - wrong length"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule alert(test + " is not a valid postcode - cannot start with a number"); document.registerform.b_zipcode.focus(); return false; } if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule alert(test + " is not a valid postcode - alpha character in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule alert(test + " is not a valid postcode - number in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule alert(test + " is not a valid postcode - number in wrong position"); document.registerform.b_zipcode.focus(); return false; } if (!(test.charAt(size-4) == " ")){//space in position length-3 rule alert(test + " is not a valid postcode - no space or space in wrong position"); document.registerform.b_zipcode.focus(); return false; } count1 = test.indexOf(" ");count2 = test.lastIndexOf(" "); if (count1 != count2){//only one space rule alert(test + " is not a valid postcode - only one space allowed"); document.registerform.b_zipcode.focus(); return false; } alert("Postcode Format OK"); return true; } </script> {/literal} <!-- END OF: POST CODE VALIDATION SCRIPT! -->


File: /customer/main/register.tpl
HTML Code:
{* $Id: register.tpl,v 1.51.2.11 2008/04/03 10:34:21 joy Exp $ *} {if $av_error eq 1} {include file="modules/UPS_OnLine_Tools/register.tpl"} {else} {if $js_enabled eq 'Y'} {include file="check_email_script.tpl"} {include file="check_zipcode_js.tpl"} {include file="generate_required_fields_js.tpl"} {include file="check_required_fields_js.tpl"} {if $config.General.use_js_states eq 'Y'} {include file="change_states_js.tpl"} {/if} {/if} {if $action ne "cart"} {if $newbie eq "Y"} {if $login ne ""} {assign var="title" value=$lng.lbl_modify_profile} {else} {assign var="title" value=$lng.lbl_create_profile} {/if} {else} {if $main eq "user_add"} {assign var="title" value=$lng.lbl_create_customer_profile} {else} {assign var="title" value=$lng.lbl_modify_customer_profile} {/if} {/if} {include file="page_title.tpl" title=$title} <!-- IN THIS SECTION --> {if $newbie ne "Y"} {include file="dialog_tools.tpl"} {/if} <!-- IN THIS SECTION --> {if $usertype ne "C"} <br /> {if $main eq "user_add"} {$lng.txt_create_customer_profile} {else} {$lng.txt_modify_customer_profile} {/if} <br /><br /> {/if} {/if} <font class="Text"> {if $newbie eq "Y"} {if $registered eq ""} {if $mode eq "update"} {$lng.txt_modify_profile_msg} {else} {$lng.txt_create_profile_msg} {/if} {/if} <br /><br /> {/if} {$lng.txt_fields_are_mandatory} </font> <br /><br /> {capture name=dialog} {if $newbie ne "Y" and $main ne "user_add" and ($usertype eq "P" and $active_modules.Simple_Mode eq "Y" or $usertype eq "A")} <div align="right">{include file="buttons/button.tpl" button_title=$lng.lbl_return_to_search_results href="users.php?mode=search"}</div> {/if} {assign var="reg_error" value=$top_message.reg_error} {assign var="error" value=$top_message.error} {assign var="emailerror" value=$top_message.emailerror} {if $registered eq ""} {if $reg_error} <font class="Star"> {if $reg_error eq "F" } {$lng.txt_registration_error} {elseif $reg_error eq "E" } {$lng.txt_email_already_exists} {elseif $reg_error eq "U" } {$lng.txt_user_already_exists} {/if} </font> <br /> {/if} {if $error ne ""} <font class="Star"><strong> {if $error eq "b_statecode"} {$lng.err_billing_state} {elseif $error eq "s_statecode"} {$lng.err_shipping_state} {elseif $error eq "b_county"} {$lng.err_billing_county} {elseif $error eq "s_county"} {$lng.err_shipping_county} {elseif $error eq "email"} {$lng.txt_email_invalid} {elseif $error eq "username"} {$lng.err_username_invalid} {else} {$error} {/if} </strong></font> <br /> {/if} <script type="text/javascript" language="JavaScript 1.2"> <!-- var is_run = false; function check_registerform_fields() {ldelim} if(is_run) return false; is_run = true; if (check_zip_code(){if $default_fields.email.avail eq 'Y'} && checkEmailAddress(document.registerform.email, '{$default_fields.email.required}'){/if} {if $config.General.check_cc_number eq "Y" AND $config.General.disable_cc ne "Y"}&& checkCCNumber(document.registerform.card_number,document.registerform.card_type) {/if}&& checkRequired(requiredFields)) {ldelim} document.registerform.submit(); return true; {rdelim} is_run = false; return false; {rdelim} --> </script> <form action="{$register_script_name}?{$smarty.server.QUERY_STRING|amp}" method="post" name="registerform" {if $js_enabled eq 'Y'}onsubmit="javascript: check_registerform_fields() + postit(); return false;"{/if}> {if $config.Security.use_https_login eq "Y"} <input type="hidden" name="{$XCARTSESSNAME}" value="{$XCARTSESSID}" /> {/if} <table cellspacing="1" cellpadding="2" width="100%"> <tbody> {include file="main/register_personal_info.tpl" userinfo=$userinfo} {include file="main/register_billing_address.tpl" userinfo=$userinfo} {include file="main/register_shipping_address.tpl" userinfo=$userinfo} {include file="main/register_contact_info.tpl" userinfo=$userinfo} {include file="main/register_additional_info.tpl" section='A'} {if $config.General.disable_cc ne "Y"} {include file="main/register_ccinfo.tpl"} {/if} {include file="main/register_account.tpl" userinfo=$userinfo} {if $active_modules.Special_Offers and $usertype ne "C"} {include file="modules/Special_Offers/customer/register_bonuses.tpl"} {/if} {if $active_modules.News_Management and $newslists} {include file="modules/News_Management/register_newslists.tpl" userinfo=$userinfo} {/if} {if $active_modules.Image_Verification and $show_antibot.on_registration eq 'Y' and $display_antibot} {assign var="antibot_err" value=$reg_antibot_err} {include file="modules/Image_Verification/spambot_arrest.tpl" mode="advanced" id=$antibot_sections.on_registration} {/if} <tr> <td colspan="3" align="center"> <br /><br /> {if $newbie eq "Y"} {$lng.txt_terms_and_conditions_newbie_note} {/if} </td> </tr> <tr> <td colspan="2"> </td> <td> {if $smarty.get.mode eq "update"} <input type="hidden" name="mode" value="update" /> {/if} <input type="hidden" name="anonymous" value="{$anonymous}" /> {if $js_enabled and $usertype eq "C"} {include file="buttons/submit.tpl" type="input" style="button" href="javascript: return check_registerform_fields() + postit(); return false;"} {else} <input type="submit" value=" {$lng.lbl_submit|strip_tags:false|escape} " /> {/if} </td> </tr> </tbody> </table> <input type="hidden" name="usertype" value="{if $smarty.get.usertype ne ""}{$smarty.get.usertype|escape:"html"}{else}{$usertype}{/if}" /> </form> <br /><br /> {if $newbie eq "Y"} {$lng.txt_newbie_registration_bottom} <br /><a href="help.php?section=conditions" target="_blank"><font class="Text" style="white-space: nowrap;"><b>{$lng.lbl_terms_n_conditions}</b> </font>{include file="buttons/go.tpl"}</a> {else} {$lng.txt_user_registration_bottom} {/if} <br /> {if $is_areas.S eq 'Y' or $is_areas.B eq 'Y'} {if $active_modules.UPS_OnLine_Tools and $av_enabled eq "Y"} <br /> <br /> <br /> <table cellpadding="1" cellspacing="1" width="100%"> <tbody> <tr> <td colspan="3"> {include file="modules/UPS_OnLine_Tools/ups_av_notice.tpl" postoffice=1} {include file="modules/UPS_OnLine_Tools/ups_av_notice.tpl"} <br /><br /> </td> </tr> </tbody> </table> {/if} {/if} {else} {if $smarty.post.mode eq "update" or $smarty.get.mode eq "update"} {$lng.txt_profile_modified} {elseif $smarty.get.usertype eq "B" or $usertype eq "B"} {$lng.txt_partner_created} {else} {$lng.txt_profile_created} {/if} {/if} {/capture} {include file="dialog.tpl" title=$lng.lbl_profile_details content=$smarty.capture.dialog extra='width="100%"'} {/if}

Any suggestions?

Regards,
Jeremy
__________________
Version 4.1.11 on Linux (Fedora)
X-Cart Gold
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:08 AM.

   

 
X-Cart forums © 2001-2020