This question has been answered by anso. See the first response.
$value = $value; // the input value in the field math $op1 = $_POST['op1'] ; // value of field op1 $op2 = $_POST['op1'] ; // value of field op1 $operator = $_POST['operator'] ; // value of field operator (should be + or - ) switch($operator){ case '+': $goodresult = $op1 + $op2; // result if operator is 'plus' ... if($value!=$goodresult){ // if answer not equal expected result $validator->addError('math', 'The answer is false.'); return false; } break; case '-': $goodresult = $op1 - $op2; if($value!=$goodresult){ $validator->addError('math', 'The answer is false.'); return false; } break; } return true;
[[!FormIt? &hooks=`email,redirect,math` &emailTpl=`email` &emailSubject=`Website Inquiry` &emailTo=`[email protected]` &emailCC=`[[+email]]` &emailFromName=`[[+name]]` &redirectTo=`27` &customValidators=`mathValidator`, // this line &validate=`math:required:mathValidator` // and this one ]]
$op1 = $_POST['op1'] ; $op2 = $_POST['op1'] ; // there's an error here it should be 'op2' not 'op1' (too fast copy/paste)
$op1 = intval( $_POST['op1']) ; // intval() to be sure the value of op1 and op2 are treated as numbers $op2 = intval($_POST['op2']) ;
$modx->log(modX::LOG_LEVEL_ERROR, 'value :' . $value);
$validator->addError('nameofyourfield', 'the value should be '.$value);
$captcha_image= '<img '. 'onclick="this.src=' . "'" . $this->modx->getOption('assets_url') . "components/captcha/captcha.php?rand='" . "+Math.floor(Math.random()*200);".'"' .' src="'. $this->modx->getOption('assets_url') . 'components/captcha/captcha.php?rand='.rand().'" alt="'.$alt.'" />'; $this->modx->setPlaceholder('spf-captcha-instructions',$captcha_prompt); $this->modx->setPlaceholder('spf-captcha-image',$captcha_image); $this->modx->setPlaceholder('spf-captcha-input-prompt',$captcha_input_prompt); $this->modx->setPlaceholder('spf-captcha-input','<input type="text" name="verify" value="" />'); $spfCaptchaTpl = $this->modx->getOption('spfcaptchaTpl',$this->spfconfig,'spfcaptchaTpl'); $this->modx->setPlaceholder('spf-captcha-stuff',$this->modx->getChunk($spfCaptchaTpl));
if (trim($value) == "") return true; // exit if blank text box
The documentation should describe (and does not) the appropriate sequence for declaring built-in hooks.