sttaq Posted January 16, 2014 Share Posted January 16, 2014 (edited) So far I have been quite impressed by out of the box features provided by Prestashop but this thing really let me down: If someone wants to register on the site or do a guest check out he can put anything as his name. Anything includes things like "---", all spaces, "***" etc. There is no validation provided here and this is really annoying. I have tried to modify the processSubmitAccount method in website\controllers\front\AuthController.php to use the Validate::isName() method but this does not help at all. It lets the users put all the strange character in the name field. I tried to create another method inside the Validate class: public static function isHumanName($name) { return preg_match('/^[A-Za-z]+$/', $name); } but for some reason this simple pattern does not work. All I want to be able to do is allow names like "FirstName MiddleName" having only one space chracter at a time and not at the start of the name. My php and regex skills are minimal and this is all I have come up with so far. Besides name I want to validate addresses and phone numbers. Addresses can have numbers in addition to letters while phone numbers can only have numbers. I guess if the problem with validating names is solved then I would be able to do it for address and numbers as well. I would appreciate if someone can put me in right direction. Thanks Edited January 16, 2014 by sttaq (see edit history) Link to comment Share on other sites More sharing options...
sttaq Posted January 20, 2014 Author Share Posted January 20, 2014 After some help and debate on StackOverflow I got my solution: preg_match('/^[A-Za-z]+(\s?[A-Za-z]+)*$/', $name); I have put above code in a method in Validate class. I then make use of this method in AuthController.php in processSubmitAccount method: if (!Validate::isHumanName($_POST['firstname'])) $this->errors[] = Tools::displayError('Please enter a valid First Name.'); This works for me for now at least! DISCLAIMER: It is not recommended to use the same regex in their production systems. You may use it as starting point but it may not work in your case. Forcing your customers to validate their names is also not recommended. Reference Link to comment Share on other sites More sharing options...
50l3r Posted April 3, 2023 Share Posted April 3, 2023 (edited) There is a way to automatically override the file src/Core/Domain/Customer/ValueObject/FirstName.php instead change directly? Im able to override override/classes/Validate.php only Edited April 3, 2023 by 50l3r (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now