Alvaro Presta Posted November 18, 2020 Share Posted November 18, 2020 Hi everyone, I am trying to add a new condition to the postcode validation, apart from the formating one, so when a customer inputs a postcode, it will be checked against the list in database. If in the list, address can be added, if not, it gives an error. I already have a list in a module folder and I think this is the issue, but I am new on this so not sure. I has considering copying the file CustomerAddressForm.php in the folder override,classes, forms and add the following code: if (($postcode = $this->getField('postcode'))) { if ($postcode->isRequired()) { $zipcode = $this->getField('postcode'); $sql = 'SELECT zipcode FROM '._DB_PREFIX_.'zipcodechecker WHERE zipcode="'.$zipcode.'" AND active="1"'; if($data != Db::getInstance()->getValue($sql)) { $postcode->addError($this->translator->trans('Sorry, we cannot deliver in that area yet')); $is_valid = false; } } } If client inputs a postcode not in the table "sql" (which is on module folder), then they will get error message and $is_valid=false. Unfortunately, the code doesn't work. I think it is due to the "sql" being in the module folder, while the CustomerAddressForm is on the override. I am new at this, so would appreciete some help here! Thanks, 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