Skip to content

Instantly share code, notes, and snippets.

@hansek
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hansek/ea2d82d73e9efc2d4b7a to your computer and use it in GitHub Desktop.
Save hansek/ea2d82d73e9efc2d4b7a to your computer and use it in GitHub Desktop.
atLeastOneOf - MODX FormIt Hook : at least one of validated field have to be correct
<?php
/**
* atLeastOneOf
*
* Custom MODX FormIt hook to check if at least one of defined field is correctly filled
*
* !!! To proper work have to be set on last validate field (phone in example)
*
* Usage example:
* &customValidators=`atLeastOneOf`
* &validate=`name:required,
* email:email:required,
* phone:required:atLeastOneOf=^email|phone^`
*
*/
$value;
$one_of = explode('|', $param);
$any_error = true;
foreach ($one_of as $one_key) {
if (!array_key_exists($one_key, $errors)) {
$any_error = false;
}
}
if (!$any_error) {
foreach ($one_of as $one_key) {
unset($validator->errors[$one_key]);
unset($validator->errorsRaw[$one_key]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment