CompareFields.php 940 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * QuickForm rule to check a date
  5. */
  6. class HTML_QuickForm_Compare_Fields extends HTML_QuickForm_Rule_Compare
  7. {
  8. /**
  9. * Function to check an array of fields
  10. * @param array of field names
  11. * @param string operator ==, >=, etc
  12. * @param string the value to compare
  13. * @return boolean True if date is valid
  14. */
  15. function validate($values = [], $operator_and_max_value = null)
  16. {
  17. if (is_array($values) && !empty($values) && !empty($operator_and_max_value)) {
  18. $final_value = 0;
  19. foreach ($values as $value) {
  20. $final_value += $value;
  21. }
  22. $params = explode('@', $operator_and_max_value);
  23. $operator = $params[0];
  24. $max_value = $params[1];
  25. return parent::validate(array($final_value, $max_value), $operator);
  26. }
  27. return false;
  28. }
  29. }