4 |
* |
* |
5 |
* $Id$ |
* $Id$ |
6 |
* |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
8 |
* @author Suren Markosyan <suren@bcsweb.com> |
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
* @package phpHtmlLib |
* @package phpHtmlLib |
10 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
23 |
* get_value() - This gets the current |
* get_value() - This gets the current |
24 |
* 'value' of the FormElement. |
* 'value' of the FormElement. |
25 |
* NOTE: This can be a 'complex' FormElement |
* NOTE: This can be a 'complex' FormElement |
26 |
* in which it may return an array of |
* in which it may return an array of |
27 |
* values. |
* values. |
28 |
* |
* |
29 |
* set_value() - Set the current value |
* set_value() - Set the current value |
31 |
* |
* |
32 |
* get_label() - returns the label for this |
* get_label() - returns the label for this |
33 |
* FormElement. |
* FormElement. |
34 |
* |
* |
35 |
* |
* |
36 |
* @package phpHtmlLib |
* @package phpHtmlLib |
37 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
104 |
*/ |
*/ |
105 |
var $_is_disabled = FALSE; |
var $_is_disabled = FALSE; |
106 |
|
|
107 |
|
/** |
108 |
|
* Indicates this element is |
109 |
|
* read only. The get_element() |
110 |
|
* will return the get_value_text() |
111 |
|
* instead of the form. |
112 |
|
*/ |
113 |
|
var $_is_readonly = FALSE; |
114 |
|
|
115 |
|
/** |
116 |
|
* Flag to tell us to enable |
117 |
|
* validation or not |
118 |
|
*/ |
119 |
|
var $_validation_enabled = TRUE; |
120 |
|
|
121 |
/** |
/** |
122 |
* automatically strip slashes from |
* automatically strip slashes from |
123 |
* form values? |
* form values? |
124 |
*/ |
*/ |
125 |
var $_stripslashes = FALSE; |
var $_stripslashes = FALSE; |
131 |
*/ |
*/ |
132 |
var $_form_name; |
var $_form_name; |
133 |
|
|
134 |
|
/** |
135 |
|
* This Form Element needs to |
136 |
|
* propogate some js to the |
137 |
|
* Form tag's onsubmit attribute |
138 |
|
* |
139 |
|
* @var string |
140 |
|
*/ |
141 |
|
var $_has_form_on_submit = false; |
142 |
|
|
143 |
|
/** |
144 |
|
* This holds an array of FormElement objects |
145 |
|
* that are slaves of this element |
146 |
|
*/ |
147 |
|
var $_slave_elements; |
148 |
|
|
149 |
|
/** |
150 |
|
* The required field string |
151 |
|
* |
152 |
|
*/ |
153 |
|
var $_required_field_marker = "*"; |
154 |
|
|
155 |
|
/** |
156 |
|
* The form Element's flag to add the : |
157 |
|
* character at the end of the label. |
158 |
|
*/ |
159 |
|
var $_label_colon_flag = FALSE; |
160 |
|
|
161 |
|
/** |
162 |
|
* variable to store JS onclick |
163 |
|
*/ |
164 |
|
var $onClickJS = NULL; |
165 |
|
|
166 |
|
/** |
167 |
|
* variable to store JS onclick |
168 |
|
*/ |
169 |
|
var $onFocusJS = NULL; |
170 |
|
|
171 |
|
/** |
172 |
|
* variable to store JS onclick |
173 |
|
*/ |
174 |
|
var $onChangeJS = NULL; |
175 |
|
|
176 |
|
/** |
177 |
|
* variable to store JS onclick |
178 |
|
*/ |
179 |
|
var $onSubmitJS = NULL; |
180 |
|
|
181 |
|
/** |
182 |
|
* variable to store JS onclick |
183 |
|
*/ |
184 |
|
var $onBlurJS = NULL; |
185 |
|
|
186 |
/** |
/** |
187 |
* The constructor |
* The constructor |
201 |
$this->set_value( $this->get_init_value() ); |
$this->set_value( $this->get_init_value() ); |
202 |
} |
} |
203 |
|
|
204 |
|
/** |
205 |
|
* This function will return the |
206 |
|
* slaves of this element |
207 |
|
* |
208 |
|
* @return array of slave elements |
209 |
|
*/ |
210 |
|
function &get_slave_elements() { |
211 |
|
return $this->_slave_elements; |
212 |
|
} |
213 |
|
|
214 |
|
/** |
215 |
|
* This function will set the |
216 |
|
* slaves of this element |
217 |
|
* |
218 |
|
* @param array of slave elements (element references &) |
219 |
|
*/ |
220 |
|
function set_slave_elements($slaveElements) { |
221 |
|
$this->_slave_elements = $slaveElements; |
222 |
|
$this->set_data_all_slaves( $this->get_value() ); |
223 |
|
} |
224 |
|
|
225 |
|
|
226 |
|
/** |
227 |
|
* This function will set the |
228 |
|
* data the parent wants to set for the slave |
229 |
|
* |
230 |
|
* @param the slave |
231 |
|
* @param the value being set for the parent |
232 |
|
*/ |
233 |
|
function set_slave_data(&$slave, $parentValue) { |
234 |
|
; //override to set the data for the slave |
235 |
|
} |
236 |
|
|
237 |
/** |
/** |
238 |
* This function will return the |
* This function will return the |
255 |
} |
} |
256 |
|
|
257 |
/** |
/** |
258 |
|
* This method sets the flag to have ALL of the |
259 |
|
* FormElement's labels be appended with a : |
260 |
|
* character. Some folks like this for some |
261 |
|
* completely unexplained reason. |
262 |
|
*/ |
263 |
|
function set_colon_flag($flag=TRUE) { |
264 |
|
$this->_label_colon_flag = $flag; |
265 |
|
} |
266 |
|
|
267 |
|
/** |
268 |
* This function will return the |
* This function will return the |
269 |
* elements value |
* elements value |
270 |
* |
* |
271 |
* @return mixed |
* @return mixed |
272 |
*/ |
*/ |
273 |
function get_value() { |
function get_value() { |
274 |
|
|
275 |
if ($this->_stripslashes) { |
if ($this->_stripslashes) { |
276 |
return stripslashes($this->_value); |
if (is_array($this->_value)) { |
277 |
|
return array_map('stripslashes', array_map('trim', $this->_value)); |
278 |
|
} else { |
279 |
|
return stripslashes(trim($this->_value)); |
280 |
|
} |
281 |
} else { |
} else { |
282 |
return $this->_value; |
if (is_array($this->_value)) { |
283 |
|
if (is_string($this->_value)) { |
284 |
|
return array_map('trim', $this->_value); |
285 |
|
} else { |
286 |
|
return $this->_value; |
287 |
|
} |
288 |
|
} else { |
289 |
|
if (is_string($this->_value)) { |
290 |
|
return trim($this->_value); |
291 |
|
} else { |
292 |
|
return $this->_value; |
293 |
|
} |
294 |
|
} |
295 |
} |
} |
296 |
} |
} |
297 |
|
|
298 |
|
|
299 |
/** |
/** |
300 |
* This function will set the |
* This function will set the |
301 |
* initial value for the element |
* initial value for the element |
304 |
*/ |
*/ |
305 |
function set_value($value) { |
function set_value($value) { |
306 |
$this->_value = $value; |
$this->_value = $value; |
307 |
|
$this->set_data_all_slaves($value); |
308 |
|
} |
309 |
|
|
310 |
|
/** |
311 |
|
* This function will call set_slave_data for all slaves |
312 |
|
* should be called when value of parent changes |
313 |
|
* |
314 |
|
* @param string - the current value of parent |
315 |
|
*/ |
316 |
|
function set_data_all_slaves($parentValue){ |
317 |
|
$slaves = &$this->get_slave_elements(); |
318 |
|
$num_slaves = count($slaves); |
319 |
|
if ($num_slaves) { |
320 |
|
for($i=0; $i < $num_slaves; $i++){ |
321 |
|
$this->set_slave_data($slaves[$i], $parentValue); |
322 |
|
} |
323 |
|
|
324 |
|
} |
325 |
} |
} |
326 |
|
|
327 |
/** |
/** |
328 |
* in case anyone in JS land |
* in case anyone in JS land |
329 |
* needs the name of the form that |
* needs the name of the form that |
330 |
* this element lives in |
* this element lives in |
331 |
* |
* |
332 |
* @param string - the form name |
* @param string - the form name |
333 |
*/ |
*/ |
334 |
function set_form_name($name) { |
function set_form_name($name) { |
338 |
/** |
/** |
339 |
* This provides a method |
* This provides a method |
340 |
* for the FormContent |
* for the FormContent |
341 |
* to get access to the |
* to get access to the |
342 |
* text associated with a |
* text associated with a |
343 |
* field. This is only available |
* field. This is only available |
344 |
* on FormElements that have text |
* on FormElements that have text |
345 |
* associated with a field. |
* associated with a field. |
346 |
* It is used during Confirmation |
* It is used during Confirmation |
347 |
* |
* |
348 |
* @param mixed - the value to look up |
* @param mixed the value to look up |
349 |
* @return string - the text associated |
* @return string - the text associated |
350 |
*/ |
*/ |
351 |
function get_value_text($value) { |
function get_value_text() { |
352 |
return $this->get_value(); |
return $this->get_value(); |
353 |
} |
} |
354 |
|
|
392 |
*/ |
*/ |
393 |
function set_disabled($flag) { |
function set_disabled($flag) { |
394 |
$this->_is_disabled = $flag; |
$this->_is_disabled = $flag; |
395 |
|
if ($flag) { |
396 |
|
//we should make sure there was no |
397 |
|
//value posted in the request, or |
398 |
|
//someone tried to hack us. |
399 |
|
if (isset($_REQUEST[str_replace("[]","",$this->get_element_name())])) { |
400 |
|
//HACK ATTEMPT! |
401 |
|
$this->_has_error = TRUE; |
402 |
|
$this->_errors[] = array('label' => $this->get_label_text(), |
403 |
|
'message' => 'Hack attempt discovered. Disabled Element has been submitted'); |
404 |
|
} |
405 |
|
} |
406 |
} |
} |
407 |
|
|
408 |
/** |
/** |
415 |
return $this->_is_disabled; |
return $this->_is_disabled; |
416 |
} |
} |
417 |
|
|
418 |
|
|
419 |
|
/** |
420 |
|
* This sets the readonly flag. |
421 |
|
* When this flag is set, the FormContent |
422 |
|
* gets back the get_value_text() instead |
423 |
|
* of get_element(). |
424 |
|
* |
425 |
|
* @param bool TRUE = readonly |
426 |
|
*/ |
427 |
|
function set_readonly($flag=TRUE) { |
428 |
|
$this->_is_readonly = $flag; |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
|
* Is this element in read only mode? |
433 |
|
* |
434 |
|
* @return bool |
435 |
|
*/ |
436 |
|
function is_readonly() { |
437 |
|
return $this->_is_readonly; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
/** |
/** |
442 |
* This sets the stripslashes flag for |
* This sets the stripslashes flag for |
443 |
* this object. |
* this object. |
498 |
$this->_style_attributes[$name] = $value; |
$this->_style_attributes[$name] = $value; |
499 |
} |
} |
500 |
|
|
501 |
|
/** |
502 |
|
* Sets the element's tab index |
503 |
|
* |
504 |
|
* @param int the # for the tabindex |
505 |
|
*/ |
506 |
|
function set_tabindex($index) { |
507 |
|
$this->set_attribute('tabindex', $index); |
508 |
|
} |
509 |
|
|
510 |
|
/** |
511 |
|
* Gets the current tab index if any |
512 |
|
* |
513 |
|
* @return int returns 0 if there is none set. |
514 |
|
*/ |
515 |
|
function get_tabindex() { |
516 |
|
if (isset($this->_attributes['tabindex'])) { |
517 |
|
return $this->_attributes['tabindex']; |
518 |
|
} else { |
519 |
|
return 0; |
520 |
|
} |
521 |
|
} |
522 |
|
|
523 |
|
|
524 |
/********* Error handling methods *********/ |
/********* Error handling methods *********/ |
525 |
|
|
544 |
} |
} |
545 |
|
|
546 |
/** |
/** |
547 |
* This returns the array of errors |
* This returns the array of errors |
548 |
* for this element |
* for this element |
549 |
* |
* |
550 |
* @param array of errors |
* @param array of errors |
551 |
*/ |
*/ |
552 |
function get_errors() { |
function get_errors() { |
574 |
if ($label==NULL) { |
if ($label==NULL) { |
575 |
return $this->_has_error; |
return $this->_has_error; |
576 |
} else { |
} else { |
|
//xxx( $label ); |
|
577 |
//they are looking for a specific error |
//they are looking for a specific error |
578 |
foreach( $this->_errors as $error) { |
foreach( $this->_errors as $error) { |
579 |
|
|
580 |
if ($error['label'] == $label) { |
if ($error['label'] == $label) { |
|
xxx( $error['label'] ); |
|
581 |
return TRUE; |
return TRUE; |
582 |
} |
} |
583 |
} |
} |
584 |
return FALSE; |
return FALSE; |
585 |
} |
} |
|
|
|
586 |
} |
} |
587 |
|
|
588 |
|
|
595 |
* |
* |
596 |
*/ |
*/ |
597 |
function create_element_name() { |
function create_element_name() { |
598 |
|
$this->set_element_name($this->_sanitize_string($this->get_label_text())); |
599 |
|
} |
600 |
|
|
|
$name = strtolower($this->get_label_text()); |
|
|
$len = strlen($name); |
|
601 |
|
|
602 |
|
/** |
603 |
|
* This private method sanitizes a string for |
604 |
|
* putting in a form element attribute value |
605 |
|
* |
606 |
|
* @param string the string to sanitize |
607 |
|
* @return string |
608 |
|
*/ |
609 |
|
function _sanitize_string($name) { |
610 |
|
$len = strlen($name); |
611 |
for ($i=0; $i<$len;$i++) { |
for ($i=0; $i<$len;$i++) { |
612 |
if ((ord($name[$i])<97 || ord($name[$i])>122) && (ord($name[$i])<48 || ord($name[$i])>57)) |
if ((ord($name[$i])<97 || ord($name[$i])>122) && |
613 |
|
(ord($name[$i])<48 || ord($name[$i])>57) && |
614 |
|
(ord($name[$i])<65 || ord($name[$i])>90)) |
615 |
$name[$i] = "_"; |
$name[$i] = "_"; |
616 |
} |
} |
617 |
|
|
618 |
|
return $name; |
619 |
|
} |
620 |
|
|
621 |
|
/** |
622 |
|
* This allows you to force the element |
623 |
|
* name to whatever you like, so you |
624 |
|
* don't have to use the default name, which is |
625 |
|
* generated based on the label. |
626 |
|
* |
627 |
|
* @param string the form element's name |
628 |
|
* @return none |
629 |
|
*/ |
630 |
|
function set_element_name($name) { |
631 |
$this->_element_name = $name; |
$this->_element_name = $name; |
632 |
} |
} |
633 |
|
|
644 |
|
|
645 |
/********* Validation methods *********/ |
/********* Validation methods *********/ |
646 |
|
|
647 |
|
/** |
648 |
|
* This method sets a flag to enable/disable |
649 |
|
* validation for the Element. |
650 |
|
* |
651 |
|
* @param boolean TRUE = enable validation |
652 |
|
*/ |
653 |
|
function enable_validation($flag=TRUE) { |
654 |
|
$this->_validation_enabled = $flag; |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
/** |
/** |
659 |
* This function performs the actual validation |
* This function performs the actual validation |
692 |
} |
} |
693 |
} |
} |
694 |
|
|
695 |
if ($has_value && !$this->is_disabled()) { |
if ($has_value && !$this->is_disabled() && $this->_validation_enabled) { |
696 |
return $this->validate($_FormValidation); |
return $this->validate($_FormValidation); |
697 |
} else if ($this->is_required()) { |
} else if ($this->is_required()) { |
698 |
$this->set_error_message("This field cannot be empty"); |
$this->set_error_message("This field cannot be empty"); |
705 |
|
|
706 |
/********* JavaScript event methods *********/ |
/********* JavaScript event methods *********/ |
707 |
|
|
|
|
|
708 |
/** |
/** |
709 |
* This method is used for adding any javascript |
* This method is used for adding any javascript |
710 |
* that is used by this element. This will automatically |
* that is used by this element. This will automatically |
716 |
return NULL; |
return NULL; |
717 |
} |
} |
718 |
|
|
719 |
|
/** |
720 |
|
* This method sets the onclick javascript |
721 |
|
* @param string - js code |
722 |
|
*/ |
723 |
|
function set_onClick($js){ |
724 |
|
$this->onClickJS = $js; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
/** |
/** |
729 |
* This function return the javaScript code for |
* This function return the javaScript code for |
730 |
* an onClick event |
* an onClick event |
731 |
* |
* Note: if you override this function be sure to use |
732 |
|
* the appropriate $this->onClickJS and append your |
733 |
|
* JS to it before returning |
734 |
* @return string - javascript code |
* @return string - javascript code |
735 |
*/ |
*/ |
736 |
function onClick() { |
function onClick() { |
737 |
return NULL; |
return $this->onClickJS; |
738 |
} |
} |
739 |
|
|
740 |
|
/** |
741 |
|
* This method sets the onfocus javascript |
742 |
|
* @param string - js code |
743 |
|
*/ |
744 |
|
function set_onFocus($js){ |
745 |
|
$this->onFocusJS = $js; |
746 |
|
} |
747 |
|
|
748 |
/** |
/** |
749 |
* This function return the javaScript code for |
* This function return the javaScript code for |
750 |
* an onFocus event |
* an onFocus event |
751 |
* |
* Note: if you override this function be sure to use |
752 |
|
* the appropriate $this->onClickJS and append your |
753 |
|
* JS to it before returning |
754 |
* @return string - javascript code |
* @return string - javascript code |
755 |
*/ |
*/ |
756 |
function onFocus() { |
function onFocus() { |
757 |
return NULL; |
return $this->onFocusJS; |
758 |
} |
} |
759 |
|
|
760 |
|
/** |
761 |
|
* This method sets the onSubmit javascript |
762 |
|
* @param string - js code |
763 |
|
*/ |
764 |
|
function set_onSubmit($js){ |
765 |
|
$this->onSubmitJS = $js; |
766 |
|
} |
767 |
|
|
768 |
/** |
/** |
769 |
* This function return the javaScript code for |
* This function return the javaScript code for |
770 |
* an onSubmit event |
* an onSubmit event |
771 |
* |
* Note: if you override this function be sure to use |
772 |
|
* the appropriate $this->onClickJS and append your |
773 |
|
* JS to it before returning |
774 |
* @return string - javascript code |
* @return string - javascript code |
775 |
*/ |
*/ |
776 |
function onSubmit() { |
function onSubmit() { |
777 |
return NULL; |
return $this->onSubmitJS; |
778 |
} |
} |
779 |
|
|
780 |
|
/** |
781 |
|
* This method sets the onblur javascript |
782 |
|
* @param string - js code |
783 |
|
*/ |
784 |
|
function set_onBlur($js){ |
785 |
|
$this->onBlurJS = $js; |
786 |
|
} |
787 |
|
|
788 |
/** |
/** |
789 |
* This function return the javaScript code for |
* This function return the javaScript code for |
790 |
* an onBlur event |
* an onBlur event |
791 |
* |
* Note: if you override this function be sure to use |
792 |
|
* the appropriate $this->onClickJS and append your |
793 |
|
* JS to it before returning |
794 |
* @return string - javascript code |
* @return string - javascript code |
795 |
*/ |
*/ |
796 |
function onBlur() { |
function onBlur() { |
797 |
return NULL; |
return $this->onBlurJS; |
798 |
} |
} |
799 |
|
|
800 |
|
/** |
801 |
|
* This method sets the onChange javascript |
802 |
|
* @param string - js code |
803 |
|
*/ |
804 |
|
function set_onChange($js){ |
805 |
|
$this->onChangeJS = $js; |
806 |
|
} |
807 |
|
|
808 |
/** |
/** |
809 |
* this function retuns the javaScript code for |
* this function retuns the javaScript code for |
810 |
* an onChange event |
* an onChange event |
811 |
* |
* Note: if you override this function be sure to use |
812 |
|
* the appropriate $this->onClickJS and append your |
813 |
|
* JS to it before returning |
814 |
* @return string - javascript code |
* @return string - javascript code |
815 |
*/ |
*/ |
816 |
function onChange() { |
function onChange() { |
817 |
return NULL; |
return $this->onChangeJS; |
818 |
} |
} |
819 |
|
|
820 |
/** |
/** |
856 |
} |
} |
857 |
|
|
858 |
|
|
859 |
|
/** |
860 |
|
* This is a method for getting the JS needed |
861 |
|
* for the form tag's onsubmit attribute. |
862 |
|
* |
863 |
|
* @return string |
864 |
|
*/ |
865 |
|
function form_tag_onsubmit() { |
866 |
|
return ''; |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
/********* rendering methods *********/ |
/********* rendering methods *********/ |
871 |
|
|
872 |
|
|
877 |
* @return string - required symbol |
* @return string - required symbol |
878 |
*/ |
*/ |
879 |
function get_required_symbol() { |
function get_required_symbol() { |
880 |
return '*'; |
if (is_object($this->_required_field_marker)) { |
881 |
|
return $this->_required_field_marker->render(); |
882 |
|
} else { |
883 |
|
return $this->_required_field_marker; |
884 |
|
} |
885 |
|
} |
886 |
|
|
887 |
|
/** |
888 |
|
* This allows you to customize the |
889 |
|
* require string marker |
890 |
|
* |
891 |
|
* @param string |
892 |
|
*/ |
893 |
|
function set_required_symbol($symbol) { |
894 |
|
$this->_required_field_marker; |
895 |
} |
} |
896 |
|
|
897 |
/** |
/** |
924 |
$attributes[] = "disabled"; |
$attributes[] = "disabled"; |
925 |
} |
} |
926 |
|
|
927 |
|
//build the ID |
928 |
|
$attributes['id'] = $this->build_id_name(); |
929 |
|
|
930 |
return $attributes; |
return $attributes; |
931 |
} |
} |
932 |
|
|
933 |
|
|
934 |
|
|
935 |
|
/** |
936 |
|
* This private method is used to |
937 |
|
* build the id attribute value string |
938 |
|
* |
939 |
|
* @return string |
940 |
|
*/ |
941 |
|
function build_id_name() { |
942 |
|
return $this->_form_name.'_'.$this->get_element_name(); |
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
/** |
/** |
947 |
* This function builds and returns a |
* This function builds and returns a |
948 |
* label object based on the label text |
* label object based on the label text |
949 |
* and error conditions |
* and error conditions |
950 |
* |
* |
951 |
|
* @param FormContent object that holds the |
952 |
|
* required field marker |
953 |
|
* @param string this string allows us to use this |
954 |
|
* method and wrap any string as a FormElement |
955 |
|
* label. |
956 |
* @return object SPANtag |
* @return object SPANtag |
957 |
*/ |
*/ |
958 |
function get_label() { |
function get_label($form_content=NULL, $label='', $indent_flag=TRUE) { |
959 |
|
|
960 |
$label = $this->get_label_text(); |
if ($label == '') { |
961 |
|
$label = $this->get_label_text(); |
962 |
|
} |
963 |
|
|
964 |
if ($this->is_required()) $label .= ' ' . $this->get_required_symbol(); |
//check to see if the form content |
965 |
|
//is read only. |
966 |
|
if (!is_null( $form_content )) { |
967 |
|
if ($form_content->is_readonly()) { |
968 |
|
|
969 |
|
$this->set_readonly(TRUE); |
970 |
|
} |
971 |
|
} |
972 |
|
|
973 |
|
if ($this->is_required() && !$this->is_readonly()) { |
974 |
|
$text = ($form_content ? $form_content->get_required_marker() : |
975 |
|
$this->get_required_symbol()). ' '.$label; |
976 |
|
} else { |
977 |
|
if ($indent_flag) { |
978 |
|
$text = ' '.$label; |
979 |
|
} else { |
980 |
|
$text = $label; |
981 |
|
} |
982 |
|
} |
983 |
|
|
984 |
$span = html_span("formlabel", $label); |
if ($this->_label_colon_flag) { |
985 |
|
$text .= ':'; |
986 |
|
} |
987 |
|
|
988 |
|
$span = html_span("formlabel", $text); |
989 |
|
|
990 |
if ($this->has_error($label)) { |
if ($this->has_error($label)) { |
991 |
$span->set_tag_attribute("style","color:red;"); |
$span->set_tag_attribute("style","color:red;"); |
994 |
return $span; |
return $span; |
995 |
} |
} |
996 |
|
|
997 |
|
/** |
998 |
|
* This method checks to see if |
999 |
|
* this element is readonly and returns |
1000 |
|
* the get_value_text() or returns get_element() |
1001 |
|
* if it isn't readonly |
1002 |
|
* |
1003 |
|
* @param bool force readonly? |
1004 |
|
* @return mixed |
1005 |
|
*/ |
1006 |
|
function &get_form_element($force_readonly=FALSE) { |
1007 |
|
if ($force_readonly) { |
1008 |
|
$this->set_readonly(TRUE); |
1009 |
|
} |
1010 |
|
|
1011 |
|
if ($this->is_readonly()) { |
1012 |
|
return container($this->get_value_text(),$this->get_confirm_element()); |
1013 |
|
} else { |
1014 |
|
return $this->get_element(); |
1015 |
|
} |
1016 |
|
} |
1017 |
|
|
1018 |
|
|
1019 |
/** |
/** |
1020 |
* This function builds and returns the |
* This function builds and returns the |
1021 |
* form element object |
* form element object. This method |
1022 |
|
* ignores the readonly flag. |
1023 |
* |
* |
1024 |
* @return object |
* @return object |
1025 |
*/ |
*/ |
1030 |
return $span; |
return $span; |
1031 |
} |
} |
1032 |
|
|
1033 |
|
|
1034 |
|
/** |
1035 |
|
* This method returns the hidden version of this |
1036 |
|
* element for a confirmation page. |
1037 |
|
* |
1038 |
|
* NOTE: This is called by the FormProcessor only. |
1039 |
|
* It shouldn't be called manually. |
1040 |
|
* |
1041 |
|
* @return INPUTtag of type hidden |
1042 |
|
*/ |
1043 |
|
function get_confirm_element() { |
1044 |
|
$values = $this->get_value(); |
1045 |
|
$name = $this->get_element_name(); |
1046 |
|
|
1047 |
|
if (is_array($values)) { |
1048 |
|
$c = container(); |
1049 |
|
foreach ( $values as $value ) { |
1050 |
|
$c->add( form_hidden($name, $value ) ); |
1051 |
|
} |
1052 |
|
return $c; |
1053 |
|
} else { |
1054 |
|
return form_hidden($name, $this->get_value() ); |
1055 |
|
} |
1056 |
|
} |
1057 |
|
|
1058 |
} // FormElement |
} // FormElement |
1059 |
?> |
?> |