On my Revo 2.1 RC3 install, I have a problem with custom validators returning TWO error messages, one exactly as intended and one holding just the "return" value returned from the snippet. I have created a snippet to check that the field is both not empty and does not match a particular string:
<?php
$value = trim(''.$modx->getOption('value',$scriptProperties,''));
$param = trim(''.$modx->getOption('param',$scriptProperties,''));
$key = $modx->getOption('key',$scriptProperties,'');
$field_name = trim(str_replace("*", "", $param));
if (!(strcmp($value,$param)) || empty($value)) {
$success=false;
} else {
$success=true;
}
if (!$success) {
$validator->addError($key,$field_name.' is required!');
}
return $success;
This works exactly as intended but returns the following in the error placeholder:
<span class="error">Email is required!</span><span class="error"></span>
Returning zero (0) instead of "false" results in:
<span class="error">Email is required!</span><span class="error">0</span>
I have tried alternating various return values, but the second error is always returned.
UPDATE: By the way, the relevant FormIt parameters are:
&customValidators=`finot`
&validate=`full_name:finot=`Full Name *`,
phone:finot=`Phone *`,
email:finot=`Email *`:email,
message:finot=`Message *`,
blank:blank`
My error span CSS has a border and display: block, so it shows up on the site. Anything I can do to get rid of the extra error?