CompareFields.php 997 B

1234567891011121314151617181920212223242526272829303132333435
  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. *
  11. * @param array of field names
  12. * @param string operator ==, >=, etc
  13. * @param string the value to compare
  14. *
  15. * @return bool True if date is valid
  16. */
  17. public function validate($values = [], $operator_and_max_value = null)
  18. {
  19. if (is_array($values) && !empty($values) && !empty($operator_and_max_value)) {
  20. $final_value = 0;
  21. foreach ($values as $value) {
  22. $value = (float) $value;
  23. $final_value += $value;
  24. }
  25. $params = explode('@', $operator_and_max_value);
  26. $operator = $params[0];
  27. $max_value = $params[1];
  28. return parent::validate([$final_value, $max_value], $operator);
  29. }
  30. return false;
  31. }
  32. }