Keron83 Posted May 28, 2015 Share Posted May 28, 2015 (edited) Hi Everyone. I'm busy to add extra fields to the contactform. (Prestashop 1.5.6.2) Thanks to this tutorial it's all (almost) working: http://nemops.com/adding-new-fields-to-prestashop-contact-form/#.VWbyqkZcptE I've added some extra fields that needs validation. - I've created an override for: CustomerThread.php (just a the tutorial says) (see attachment) I've added the following rules to CustomerThread with some validation: 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isName'), 'address' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress'), 'postcode' => array('type' => self::TYPE_STRING, 'validate' => 'isPostCode'), 'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName'), 'number' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber') Everything is fine till one of the extra field is not valid. (example:hsfjdhsjsd as phonenumber -> is not valid) Then I get this error: Property CustomerThread->number is not valid at line 837 in file classes/ObjectModel.php 831. 832. $message = $this->validateField($field, $this->$field); 833. if ($message !== true) 834. { 835. if ($die) 836. throw new PrestaShopException($message); 837. return $error_return ? $message : false; 838. } 839. } 840. 841. return true; If the extra fields are filled in correctly everything works. Can anyone help? See also the files That I attached. CustomerThread.php ContactController.php contact-form.tpl.txt message.tpl.txt Edited May 28, 2015 by Keron83 (see edit history) Link to comment Share on other sites More sharing options...
jgamio Posted May 28, 2015 Share Posted May 28, 2015 I think you need to be more specific about your question You set 'number' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber') You set number a String but validate like isPhoneNumber ( Just number ) then you get the error because you get a word You need set another type of data or you need validate the data Link to comment Share on other sites More sharing options...
Keron83 Posted May 28, 2015 Author Share Posted May 28, 2015 Thanks. I solved it by doing it this way: //check custom fields //Check Name elseif (!($name = nl2br2(Tools::getValue('name')))) $this->errors[] = Tools::displayError('Field is required'); elseif (!preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u'), stripslashes($name))) $this->errors[] = Tools::displayError('Enter a valid name'); //Check Address elseif (!($address = nl2br2(Tools::getValue('address')))) $this->errors[] = Tools::displayError('Field is required'); elseif (!preg_match('/^[^!<>?=+@{}_$%]*$/u', $address)) $this->errors[] = Tools::displayError('Enter a valid address'); //Check Postcode elseif (!($postcode = nl2br2(Tools::getValue('postcode')))) $this->errors[] = Tools::displayError('Field is required'); elseif (!preg_match('/^[a-zA-Z 0-9-]+$/', $postcode)) $this->errors[] = Tools::displayError('Enter a valid postcode'); //Check City elseif (!($city = nl2br2(Tools::getValue('city')))) $this->errors[] = Tools::displayError('Field is required'); elseif (!preg_match('/^[^!<>;?=+@#"°{}_$%]*$/u', $city)) $this->errors[] = Tools::displayError('Enter a valid city'); //Check Phonenumber elseif (!($number = nl2br2(Tools::getValue('number')))) $this->errors[] = Tools::displayError('Field is required'); elseif (!preg_match('/^[+0-9. ()-]*$/', $number)) $this->errors[] = Tools::displayError('Enter a valid phonenumber'); This solution works for me. Link to comment Share on other sites More sharing options...
ventura Posted May 29, 2015 Share Posted May 29, 2015 (edited) You can made it with !Validate::isName !Validate::isPostCode ..... Edited May 29, 2015 by ventura (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