Last active
August 29, 2015 14:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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