Hi all
The solution I 've adopted is different (graphic captcha) but answering to @max565 the math check have to be done before SendMessage call on ContactForm.php.
I'm using version 4.4.1 of the module in Prestashop 8.1.2, and in the code of the module I put the code
$mathAnswer = Tools::getValue('mathAnswer'); $mathNumber1 = Tools::getValue('mathNumber1'); $mathNumber2 = Tools::getValue('mathNumber2'); $mathSum = $mathNumber1 + $mathNumber2;
In the very beginning of the function getWidgetVariables we can see an if clause :
public function getWidgetVariables($hookName = null, array $configuration = []) { $notifications = []; if (Tools::isSubmit('submitMessage')) { $this->sendMessage();
And there, is a good place to test the new field and return if error. Replace the line $this->sendMessage(); with Something like:
if (Tools::isSubmit('submitMessage')) { // Math test // $mathAnswer = Tools::getValue('mathAnswer'); $mathNumber1 = Tools::getValue('mathNumber1'); $mathNumber2 = Tools::getValue('mathNumber2'); if ($mathAnswer == $mathNumber1 + $mathNumber2) { $this->sendMessage(); } else { $this->context->controller->errors[] = Tools::displayError('The answer is wrong'); } ...
So if "submit", test the math. If "Ok" call sendMessage()
Hope this helps.