5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2002-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
16 # ---- PUBLIC INTERFACE --------------------------------------------------
32 function FormField($Name, $IsRequired, $Label, $ValidFunc, $ValidMsgs)
35 $this->MyName = $Name;
36 $this->MyIsRequired = $IsRequired;
37 $this->MyLabel = $Label;
38 $this->MyValidFunc = $ValidFunc;
39 $this->MyValidMsgs = $ValidMsgs;
41 # attempt to set value if available
42 if (isset($_POST[$this->MyName]))
46 elseif (isset($_GET[$this->MyName]))
63 function Name($NewVal = NULL) {
return $this->GetOrSet(
"MyName", $NewVal); }
73 function IsRequired($NewVal = NULL) {
return $this->GetOrSet(
"MyIsRequired", $NewVal); }
80 function Label($NewVal = NULL) {
return $this->GetOrSet(
"MyLabel", $NewVal); }
88 function Value($NewVal = NULL) {
return $this->GetOrSet(
"MyValue", $NewVal); }
94 function IsPassword() {
return method_exists($this,
"PasswordFormField"); }
110 $this->PrintInput($DisplayErrorIndicator);
122 print(($DisplayErrorIndicator ?
"<span style=\"color: red;\"" :
"")
123 .
"<label for=\"".$this->MyName.
"\">".$this->MyLabel.
"</label>"
124 .($DisplayErrorIndicator ?
"</span>" :
"")
138 # assume value is valid
141 # if custom validation function supplied
142 if ($this->MyValidFunc)
144 # call custom function and return code
146 $ErrorCode = $ValidFunc($this->MyName, $Value);
150 # if value is required and none is set
151 if ($this->MyIsRequired && !strlen($Value)
152 && !method_exists($this,
"PasswordFormField"))
154 # return code indicating missing value
159 # return error code (if any) to caller
171 0 =>
"This value is valid.",
172 1 =>
"%L is a required value.",
174 if (isset($this->MyValidMsgs[$ErrorCode]))
176 $Message = $this->MyValidMsgs[$ErrorCode];
180 $Message = isset($Messages[$ErrorCode])
181 ? $Messages[$ErrorCode] :
182 "INTERNAL ERROR - Invalid Error Code (Field = %N, Code = %C)";
189 # ---- PRIVATE INTERFACE -------------------------------------------------
205 private function GetOrSet($ValueName, $NewValue)
207 if ($NewValue !== NULL)
209 $this->{$ValueName} = $NewValue;
211 return $this->{$ValueName};