Source for file FormFieldSet.class.php

Documentation is available at FormFieldSet.class.php

  1. <?php
  2. /**
  3. * @package harmoni.utilities
  4. */
  5.  
  6. require_once HARMONI."utlities/FieldSetValidator/FieldSet.class.php";
  7.  
  8. /**
  9. *
  10. * @package harmoni.utilities
  11. *
  12. * @copyright Copyright &copy; 2005, Middlebury College
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  14. *
  15. * @version $Id: FormFieldSet.class.php,v 1.3 2005/02/04 15:59:13 adamfranco Exp $
  16. */
  17. class FormFieldSet extends FieldSet {
  18.  
  19. var $_changed;
  20. var $_valid;
  21. function FormFieldSet( $fields = null ) {
  22. $this->_changed=array();
  23. $this->_valid = array();
  24. if ($fields && is_array($fields)) {
  25. foreach (array_keys($fields) as $k) {
  26. $this->_changed[$k] = false;
  27. $this->_valid[$k] = true;
  28. }
  29. }
  30. parent::FieldSet( $fields );
  31. }
  32. function set( $key, $val ) {
  33. $oldVal = $this->get($key);
  34. if ($oldVal == $val) return; // we would use '===' here, but we can't be sure
  35. // that form data from the user will be of the same
  36. // variable type. ie, "5" == 5 is true, but "5" === 5
  37. // is not
  38. parent::set($key,$val);
  39. $this->_changed[$key] = true;
  40. }
  41. function clear() {
  42. $this->_changed = array();
  43. parent::clear();
  44. }
  45. function validate( $key, $rule, $error = null, $errorHandler=null ) {
  46. if (!$rule->check($this->get($key))) {
  47. $this->_valid[$key] = false;
  48. if ($error) {
  49. if (!$errorHandler) $errorHandler=&Services::getService("UserError");
  50. $errorHandler->addError($error);
  51. return false;
  52. }
  53. }
  54. return true;
  55. }
  56. function hasErrors() {
  57. foreach ($this->_valid as $v) {
  58. if (!$v) return false;
  59. }
  60. return true;
  61. }
  62. function changed($key) {
  63. return $this->_changed[$key];
  64. }
  65. }
  66.  
  67. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:21 -0400 by phpDocumentor 1.3.0RC3