Source for file Form.php

Documentation is available at Form.php

  1. <?php
  2.  
  3. /**
  4. * MVCnPHP - Form.class.php
  5. *
  6. * This source file is subject to version 2.02 of the PHP license,
  7. * that is bundled with this package in the file LICENSE, and is
  8. * available at through the world-wide-web at
  9. * http://www.php.net/license/2_02.txt.
  10. * If you did not receive a copy of the PHP license and are unable to
  11. * obtain it through the world-wide-web, please send a note to
  12. * license@php.net so we can mail you a copy immediately.
  13. *
  14. * @author Tony Bibbs <tony@geeklog.net>
  15. * @copyright Tony Bibbs 2003
  16. * @package net.geeklog.mvc
  17. * @version $Id: Form.class.php,v 1.3 2003/08/28 01:31:22 tony Exp $
  18. *
  19. */
  20.  
  21. /**
  22. * This is a basic form class that can aid in form validation and
  23. * manipulation.
  24. *
  25. * @author Tony Bibbs <tony@geeklog.net>
  26. * @package net.geeklog.mvc
  27. *
  28. */
  29. class MVCnPHP_Form {
  30. /**
  31. * @access private
  32. * @var array
  33. */
  34. private $values = null;
  35. /**
  36. * Constructor
  37. *
  38. * @author Tony Bibbs <tony@geeklog.net>
  39. * @access public
  40. * @param array $formArray Array of form fieds (typical $_GET, $_POST or $_REQUEST)
  41. *
  42. */
  43. public function Form($formArray)
  44. {
  45. $this->values = $formArray;
  46. }
  47. /**
  48. * Returns if the given variable name exists in form
  49. *
  50. * @author Tony Bibbs <tony@geeklog.net>
  51. * @access public
  52. * @param string $varName Name of form variable
  53. * @return boolean True if found, otherwise false
  54. *
  55. */
  56. public function contains($varName)
  57. {
  58. return isset($this->values[$varName]);
  59. }
  60. /**
  61. * Gets value for given variable name
  62. *
  63. * @author Tony Bibbs <tony@geeklog.net>
  64. * @access public
  65. * @param string $varName Name of form variable to get value for
  66. * @return variant Value of form variable
  67. *
  68. */
  69. public function get($varName)
  70. {
  71. if (!$this->contains($varName)) {
  72. return null;
  73. }
  74. return $this->values[$varName];
  75. }
  76. /**
  77. * Deletes a form variable
  78. *
  79. * @author Tony Bibbs <tony@geeklog.net>
  80. * @access public
  81. * @param string $varName Name of form variable to delete
  82. *
  83. */
  84. public function remove($varName)
  85. {
  86. if ($this->contains($varName)) {
  87. unset($this->values[$varName]);
  88. }
  89. }
  90. /**
  91. * Sets a field to given value
  92. *
  93. * @author Tony Bibbs <tony@geeklog.net>
  94. * @access public
  95. * @param string $varName Name of field to set
  96. * @param string $value Value to set field to
  97. *
  98. */
  99. public function set($varName, $value)
  100. {
  101. $this->values[$varName] = $value;
  102. }
  103. /**
  104. * Returns value array
  105. *
  106. * @author Tony Bibbs <tony@geeklog.net>
  107. * @access public
  108. * @return array Values array
  109. *
  110. */
  111. public function &getValues()
  112. {
  113. return $this->values;
  114. }
  115. }
  116.  
  117. ?>

Documentation generated on Mon, 7 Mar 2005 22:36:21 -0600 by phpDocumentor 1.3.0RC3