CompareFields.php 989 B

123456789101112131415161718192021222324252627282930313233
  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. public 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. $value = (float) $value;
  21. $final_value += $value;
  22. }
  23. $params = explode('@', $operator_and_max_value);
  24. $operator = $params[0];
  25. $max_value = $params[1];
  26. return parent::validate(array($final_value, $max_value), $operator);
  27. }
  28. return false;
  29. }
  30. }