[[!FormIt? &validate=`other_text:condRequired=`testfield|testvalue` `]]
<?php
// get test field and value
$param = explode('|',$param);
// test if field is an array or not -- work with options and other field types
if ( is_array($validator->fields[$param[0]]) ) {
$field = $validator->fields[$param[0]][0];
} else {
$field = $validator->fields[$param[0]];
}
// is test field set to test value?
if ($field == $param[1]) {
// is the required field empty?
$value = trim($value);
if (empty($value)) {
$validator->addError($key,'This field is required');
return false;
}
}
return true;
?>
[[!FormIt? &validate=`other_text:condRequired=`testfield|testvalue|My custom error message.` `]]
<?php
// get test field and value
$param = explode('|',$param);
// test if field is an array or not -- work with options and other field types
if ( is_array($validator->fields[$param[0]]) ) {
$field = $validator->fields[$param[0]][0];
} else {
$field = $validator->fields[$param[0]];
}
// set the error message
$errorMssg = !empty($param[2]) ? $param[2] : 'This field is required';
// is test field set to test value?
if ($field == $param[1]) {
// is the required field empty?
$value = trim($value);
if (empty($value)) {
$validator->addError($key,$errorMssg);
return false;
}
}
return true;
?>
[[!FormIt?
&validate=`email:condRequired=`phone||Please supply an email address and/or phone number`,
phone:condRequired=`email||Please supply an email address and/or phone number` `]]
Note: I would also be in favor of returning the built-in email validator to its previous behavior of allowing empty strings through. IMO this would make it much more useful. If it’s a required email address, then you can always use :email:required. As it is now, there’s no way to validate a non-required email address field.
[[!FormIt?
&hooks=`email`
&validate=`workemail:blank,
fCheckDatenschutz:required,
fSurname:required,
fFirstname:required,
fStreetNr:required,
fPostalcodRegion:required,
fEmail:email:required,
fGeschenkSurname:condRequired=`fCheckGeschenkabo|ja|blablabla.` `
...
]]
<form>
...
<div class="formDiv clearfix formCheck">
<label for="foptCheckGeschenkabo">Geschenkabo?</label>
<input name="fCheckGeschenkabo[]" type="hidden" value="" >
<input id="foptCheckGeschenkabo"
name="fCheckGeschenkabo[]"
type="checkbox"
value="ja"
[[!+fi.fCheckGeschenkabo:FormItIsChecked=`ja`]] >
</div>
...
</form>
.
&customValidators=`condRequired`
field:condRequired=^testfield>testvalue^
field:condRequired=^testfield!=testvalue^