AbanteCart Community

Shopping Cart Operations => Support => General Support => Topic started by: Sam_78 on May 19, 2021, 11:53:47 AM

Title: Validation
Post by: Sam_78 on May 19, 2021, 11:53:47 AM
Hi,
I installed V 1.13 and on create account page how can I add validation for Zip code to accept only numbers and limit 5 digits only
I can do this via Jquery in create.tpl but is there any other way to do this without editing code ? Same for phone number and other fields.
Title: Re: Validation
Post by: abolabo on May 20, 2021, 03:55:05 AM
hi.
better way to do validation via validation hook .

public function onModelAccountCustomer_ValidateData()
{
    $that = $this->baseObject;
     if( !preg_match('[^0-9]',  $that->request->post['postcode'] ){
           $that->error['postcode'] = 'Your error text here';
     }
}
Title: Re: Validation
Post by: Sam_78 on May 20, 2021, 01:56:00 PM
Which file ?

Also, this will be server side validation so customer will be able to make a request using invalid zip-code. We can use this but I think there should be JAVASCRIPT validation before making this request.

Can you tell me the exact path for this hook ?
Title: Re: Validation
Post by: abolabo on May 20, 2021, 05:34:06 PM
hmm.. i thought you created your own custom extension to affect on base functionality.
i think you should.
Also you can create account/create.post.tpl inside your extension with your js-code to extend base accoun/create.tpl

See more details here
https://abantecart.atlassian.net/wiki/spaces/DOC/pages/17694951/Extension+Process+Overview