Jump to content

Javascritp On Address.tpl


Zen_j1

Recommended Posts

I have used a javascript i found on Internet in in address.tpl on ps 1.5 to validate the postcode entered by customer while add the address. This stop customer adding address where I donot deliver. But same javascript does not work on ps 1.6.1.3. can some help me to figure out what I am missing I have written the code 

 

<form name = "myform" form action="{$link->getPageLink('address', true)|escape:'html'}" method="post" class="std" id="add_address">

 

Preststashop 1.5 address.tpl 

code

code

code

 

</form>

 

/** I have added the javascript after </form> **/

 

<script type = "text/javascript">
{literal}
function checkZip() {

var z = document.myform.postcode;
var zv = z.value;
if (!/^\d{6}$/.test(zv)) {
alert ("Please enter a valid Pin Code");
document.myform.postcode.value = "";
myfield = z;  // note myfield must be a global variable
setTimeout('myfield.focus(); myfield.select();' , 10);  // to fix bug in Firefox
return false;
}

var codes = [111111,222222,333333,444444];  // add as many zip codes as you like, separated by commas (no comma at the end)
var found = false;
for (var i=0; i<codes.length; i++) {
if (zv == codes) {
found = true;
break;
}
}

if (!found) {
alert ("Sorry, As if now we do not deliver at this Pin Code " + zv + " . We look forward for your business in near future.");
document.myform.postcode.value = "";
return false;
}

}

{/literal}
</script>

 

 

In ps 1.6.3.1

line 42 

 

<form name = "myform" form action="{$link->getPageLink('address', true)|escape:'html':'UTF-8'}" method="post" class="std" id="add_address">

 

Preststashop 1.6.31 address.tpl 

code

code

code

 

</form>

 

Here added same javascript code as above and it does not validate and create a error pop up as in case of ps 1.5

Link to comment
Share on other sites

Ok, you need to add this code onblur="javascript:checkZip();" in line 103 and 151 in file address.tpl

example:

<input onblur="javascript:checkZip();" class="is_required validate form-control" data-validate="{$address_validation.postcode.validate}" type="text" id="postcode" name="postcode" value="{if isset($smarty.post.postcode)}{$smarty.post.postcode}{else}{if isset($address->postcode)}{$address->postcode|escape:'html':'UTF-8'}{/if}{/if}" />

Edited by im_presto (see edit history)
  • Like 1
Link to comment
Share on other sites

Fantastic.It works. I like make a request to you for I more thing. As if now validation message/Error message is displayed as pop. There might chance a pop can be blocked by browser.

 

I have seen some site display validation message/Error message just below or next to field in red how can this be done in this case. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...