8 # ---- PUBLIC INTERFACE --------------------------------------------------
23 function FormField($Name, $IsRequired, $Label, $ValidFunc, $ValidMsgs)
26 $this->MyName = $Name;
27 $this->MyIsRequired = $IsRequired;
28 $this->MyLabel = $Label;
29 $this->MyValidFunc = $ValidFunc;
30 $this->MyValidMsgs = $ValidMsgs;
32 # attempt to set value if available
33 if (isset($_POST[$this->MyName]))
37 elseif (isset($_GET[$this->MyName]))
52 function Name($NewVal = NULL) {
return $this->GetOrSet(
"MyName", $NewVal); }
61 function IsRequired($NewVal = NULL) {
return $this->GetOrSet(
"MyIsRequired", $NewVal); }
67 function Label($NewVal = NULL) {
return $this->GetOrSet(
"MyLabel", $NewVal); }
74 function Value($NewVal = NULL) {
return $this->GetOrSet(
"MyValue", $NewVal); }
80 function IsPassword() {
return method_exists($this,
"PasswordFormField"); }
95 $this->PrintInput($DisplayErrorIndicator);
106 print(($DisplayErrorIndicator ?
"<span style=\"color: red;\"" :
"")
107 .
"<label for=\"".$this->MyName.
"\">".$this->MyLabel.
"</label>"
108 .($DisplayErrorIndicator ?
"</span>" :
"")
122 # assume value is valid
125 # if custom validation function supplied
126 if ($this->MyValidFunc)
128 # call custom function and return code
130 $ErrorCode = $ValidFunc($this->MyName, $Value);
134 # if value is required and none is set
135 if ($this->MyIsRequired && !strlen($Value)
136 && !method_exists($this,
"PasswordFormField"))
138 # return code indicating missing value
143 # return error code (if any) to caller
155 0 =>
"This value is valid.",
156 1 =>
"%L is a required value.",
158 if (isset($this->MyValidMsgs[$ErrorCode]))
160 $Message = $this->MyValidMsgs[$ErrorCode];
164 $Message = isset($Messages[$ErrorCode])
165 ? $Messages[$ErrorCode] :
166 "INTERNAL ERROR - Invalid Error Code (Field = %N, Code = %C)";
173 # ---- PRIVATE INTERFACE -------------------------------------------------
182 # convenience function to handle getting and setting of values
183 private function GetOrSet($ValueName, $NewValue)
185 if ($NewValue !== NULL)
187 $this->{$ValueName} = $NewValue;
189 return $this->{$ValueName};