News:

AbanteCart v1.4.2 is released.

Main Menu
support

Validation

Started by Sam_78, May 19, 2021, 11:53:47 AM

Previous topic - Next topic

Sam_78

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.

abolabo

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';
     }
}
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Sam_78

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 ?

abolabo

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
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Forum Rules Code of conduct
AbanteCart.com 2010 -