5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2002-2015 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 32 public function __construct($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 public function Name($NewVal = NULL)
65 return $this->GetOrSet(
"MyName", $NewVal);
78 return $this->GetOrSet(
"MyIsRequired", $NewVal);
86 public function Label($NewVal = NULL)
88 return $this->GetOrSet(
"MyLabel", $NewVal);
97 public function Value($NewVal = NULL)
99 return $this->GetOrSet(
"MyValue", $NewVal);
108 return method_exists($this,
"PasswordFormField");
125 $this->PrintInput($DisplayErrorIndicator);
137 print(($DisplayErrorIndicator ?
"<span style=\"color: red;\">" :
"")
138 .
"<label for=\"".$this->MyName.
"\">".$this->MyLabel.
"</label>" 139 .($DisplayErrorIndicator ?
"</span>" :
"")
154 # assume value is valid 157 # if custom validation function supplied 158 if ($this->MyValidFunc)
160 # call custom function and return code 162 $ErrorCode = $ValidFunc($this->MyName, $Value);
166 # if value is required and none is set 167 if ($this->MyIsRequired && !strlen($Value)
168 && !method_exists($this,
"PasswordFormField"))
170 # return code indicating missing value 175 # return error code (if any) to caller 187 0 =>
"This value is valid.",
188 1 =>
"%L is a required value.",
190 if (isset($this->MyValidMsgs[$ErrorCode]))
192 $Message = $this->MyValidMsgs[$ErrorCode];
196 $Message = isset($Messages[$ErrorCode])
197 ? $Messages[$ErrorCode] :
198 "INTERNAL ERROR - Invalid Error Code (Field = %N, Code = %C)";
205 # ---- PRIVATE INTERFACE ------------------------------------------------- 221 private function GetOrSet($ValueName, $NewValue)
223 if ($NewValue !== NULL)
225 $this->{$ValueName} = $NewValue;
227 return $this->{$ValueName};