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 |
105 |
var $_is_disabled = FALSE; |
var $_is_disabled = FALSE; |
106 |
|
|
107 |
/** |
/** |
108 |
* automatically strip slashes from |
* automatically strip slashes from |
109 |
* form values? |
* form values? |
110 |
*/ |
*/ |
111 |
var $_stripslashes = FALSE; |
var $_stripslashes = FALSE; |
117 |
*/ |
*/ |
118 |
var $_form_name; |
var $_form_name; |
119 |
|
|
120 |
|
/** |
121 |
|
* This Form Element needs to |
122 |
|
* propogate some js to the |
123 |
|
* Form tag's onsubmit attribute |
124 |
|
* |
125 |
|
* @var string |
126 |
|
*/ |
127 |
|
var $_has_form_on_submit = false; |
128 |
|
|
129 |
|
/** |
130 |
|
* This holds an array of FormElement objects |
131 |
|
* that are slaves of this element |
132 |
|
*/ |
133 |
|
var $_slave_elements; |
134 |
|
|
135 |
|
/** |
136 |
|
* The required field string |
137 |
|
* |
138 |
|
*/ |
139 |
|
var $_required_field_marker = "*"; |
140 |
|
|
141 |
|
|
142 |
/** |
/** |
143 |
* The constructor |
* The constructor |
157 |
$this->set_value( $this->get_init_value() ); |
$this->set_value( $this->get_init_value() ); |
158 |
} |
} |
159 |
|
|
160 |
|
/** |
161 |
|
* This function will return the |
162 |
|
* slaves of this element |
163 |
|
* |
164 |
|
* @return array of slave elements |
165 |
|
*/ |
166 |
|
function &get_slave_elements() { |
167 |
|
return $this->_slave_elements; |
168 |
|
} |
169 |
|
|
170 |
|
/** |
171 |
|
* This function will set the |
172 |
|
* slaves of this element |
173 |
|
* |
174 |
|
* @param array of slave elements (element references &) |
175 |
|
*/ |
176 |
|
function set_slave_elements($slaveElements) { |
177 |
|
$this->_slave_elements = $slaveElements; |
178 |
|
$this->set_data_all_slaves( $this->get_value() ); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
/** |
183 |
|
* This function will set the |
184 |
|
* data the parent wants to set for the slave |
185 |
|
* |
186 |
|
* @param the slave |
187 |
|
* @param the value being set for the parent |
188 |
|
*/ |
189 |
|
function set_slave_data(&$slave, $parentValue) { |
190 |
|
; //override to set the data for the slave |
191 |
|
} |
192 |
|
|
193 |
/** |
/** |
194 |
* This function will return the |
* This function will return the |
224 |
} |
} |
225 |
} |
} |
226 |
|
|
227 |
|
|
228 |
/** |
/** |
229 |
* This function will set the |
* This function will set the |
230 |
* initial value for the element |
* initial value for the element |
233 |
*/ |
*/ |
234 |
function set_value($value) { |
function set_value($value) { |
235 |
$this->_value = $value; |
$this->_value = $value; |
236 |
|
$this->set_data_all_slaves($value); |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
|
* This function will call set_slave_data for all slaves |
241 |
|
* should be called when value of parent changes |
242 |
|
* |
243 |
|
* @param string - the current value of parent |
244 |
|
*/ |
245 |
|
function set_data_all_slaves($parentValue){ |
246 |
|
$slaves = &$this->get_slave_elements(); |
247 |
|
$num_slaves = count($slaves); |
248 |
|
if ($num_slaves) { |
249 |
|
for($i=0; $i < $num_slaves; $i++){ |
250 |
|
$this->set_slave_data($slaves[$i], $parentValue); |
251 |
|
} |
252 |
|
|
253 |
|
} |
254 |
} |
} |
255 |
|
|
256 |
/** |
/** |
257 |
* in case anyone in JS land |
* in case anyone in JS land |
258 |
* needs the name of the form that |
* needs the name of the form that |
259 |
* this element lives in |
* this element lives in |
260 |
* |
* |
261 |
* @param string - the form name |
* @param string - the form name |
262 |
*/ |
*/ |
263 |
function set_form_name($name) { |
function set_form_name($name) { |
267 |
/** |
/** |
268 |
* This provides a method |
* This provides a method |
269 |
* for the FormContent |
* for the FormContent |
270 |
* to get access to the |
* to get access to the |
271 |
* text associated with a |
* text associated with a |
272 |
* field. This is only available |
* field. This is only available |
273 |
* on FormElements that have text |
* on FormElements that have text |
274 |
* associated with a field. |
* associated with a field. |
275 |
* It is used during Confirmation |
* It is used during Confirmation |
276 |
* |
* |
277 |
* @param mixed - the value to look up |
* @param mixed the value to look up |
278 |
* @return string - the text associated |
* @return string - the text associated |
279 |
*/ |
*/ |
280 |
function get_value_text($value) { |
function get_value_text() { |
281 |
return $this->get_value(); |
return $this->get_value(); |
282 |
} |
} |
283 |
|
|
393 |
$this->_style_attributes[$name] = $value; |
$this->_style_attributes[$name] = $value; |
394 |
} |
} |
395 |
|
|
396 |
|
/** |
397 |
|
* Sets the element's tab index |
398 |
|
* |
399 |
|
* @param int the # for the tabindex |
400 |
|
*/ |
401 |
|
function set_tabindex($index) { |
402 |
|
$this->set_attribute('tabindex', $index); |
403 |
|
} |
404 |
|
|
405 |
|
/** |
406 |
|
* Gets the current tab index if any |
407 |
|
* |
408 |
|
* @return int returns 0 if there is none set. |
409 |
|
*/ |
410 |
|
function get_tabindex() { |
411 |
|
if (isset($this->_attributes['tabindex'])) { |
412 |
|
return $this->_attributes['tabindex']; |
413 |
|
} else { |
414 |
|
return 0; |
415 |
|
} |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
/********* Error handling methods *********/ |
/********* Error handling methods *********/ |
420 |
|
|
439 |
} |
} |
440 |
|
|
441 |
/** |
/** |
442 |
* This returns the array of errors |
* This returns the array of errors |
443 |
* for this element |
* for this element |
444 |
* |
* |
445 |
* @param array of errors |
* @param array of errors |
446 |
*/ |
*/ |
447 |
function get_errors() { |
function get_errors() { |
469 |
if ($label==NULL) { |
if ($label==NULL) { |
470 |
return $this->_has_error; |
return $this->_has_error; |
471 |
} else { |
} else { |
|
//xxx( $label ); |
|
472 |
//they are looking for a specific error |
//they are looking for a specific error |
473 |
foreach( $this->_errors as $error) { |
foreach( $this->_errors as $error) { |
474 |
|
|
475 |
if ($error['label'] == $label) { |
if ($error['label'] == $label) { |
|
xxx( $error['label'] ); |
|
476 |
return TRUE; |
return TRUE; |
477 |
} |
} |
478 |
} |
} |
479 |
return FALSE; |
return FALSE; |
480 |
} |
} |
|
|
|
481 |
} |
} |
482 |
|
|
483 |
|
|
499 |
$name[$i] = "_"; |
$name[$i] = "_"; |
500 |
} |
} |
501 |
|
|
502 |
|
$this->set_element_name($name); |
503 |
|
} |
504 |
|
|
505 |
|
/** |
506 |
|
* This allows you to force the element |
507 |
|
* name to whatever you like, so you |
508 |
|
* don't have to use the default name, which is |
509 |
|
* generated based on the label. |
510 |
|
* |
511 |
|
* @param string the form element's name |
512 |
|
* @return none |
513 |
|
*/ |
514 |
|
function set_element_name($name) { |
515 |
$this->_element_name = $name; |
$this->_element_name = $name; |
516 |
} |
} |
517 |
|
|
681 |
} |
} |
682 |
|
|
683 |
|
|
684 |
|
/** |
685 |
|
* This is a method for getting the JS needed |
686 |
|
* for the form tag's onsubmit attribute. |
687 |
|
* |
688 |
|
* @return string |
689 |
|
*/ |
690 |
|
function form_tag_onsubmit() { |
691 |
|
return ''; |
692 |
|
} |
693 |
|
|
694 |
|
|
695 |
/********* rendering methods *********/ |
/********* rendering methods *********/ |
696 |
|
|
697 |
|
|
702 |
* @return string - required symbol |
* @return string - required symbol |
703 |
*/ |
*/ |
704 |
function get_required_symbol() { |
function get_required_symbol() { |
705 |
return '*'; |
return $this->_required_field_marker; |
706 |
|
} |
707 |
|
|
708 |
|
/** |
709 |
|
* This allows you to customize the |
710 |
|
* require string marker |
711 |
|
* |
712 |
|
* @param string |
713 |
|
*/ |
714 |
|
function set_required_symbol($symbol) { |
715 |
|
$this->_required_field_marker; |
716 |
} |
} |
717 |
|
|
718 |
/** |
/** |
754 |
* label object based on the label text |
* label object based on the label text |
755 |
* and error conditions |
* and error conditions |
756 |
* |
* |
757 |
|
* @param FormContent object that holds the |
758 |
|
* required field marker |
759 |
* @return object SPANtag |
* @return object SPANtag |
760 |
*/ |
*/ |
761 |
function get_label() { |
function get_label($form_content=NULL) { |
762 |
|
|
763 |
$label = $this->get_label_text(); |
$label = $this->get_label_text(); |
764 |
|
$text = $label; |
765 |
|
|
766 |
if ($this->is_required()) $label .= ' ' . $this->get_required_symbol(); |
if ($this->is_required()) { |
767 |
|
$text .= ' ' . ($form_content ? $form_content->_required_field_marker : |
768 |
|
$this->get_required_symbol()); |
769 |
|
} |
770 |
|
|
771 |
$span = html_span("formlabel", $label); |
$span = html_span("formlabel", $text); |
772 |
|
|
773 |
if ($this->has_error($label)) { |
if ($this->has_error()) { |
774 |
$span->set_tag_attribute("style","color:red;"); |
$span->set_tag_attribute("style","color:red;"); |
775 |
} |
} |
776 |
|
|
791 |
return $span; |
return $span; |
792 |
} |
} |
793 |
|
|
794 |
|
|
795 |
|
/** |
796 |
|
* This method returns the hidden version of this |
797 |
|
* element for a confirmation page. |
798 |
|
* |
799 |
|
* NOTE: This is called by the FormProcessor only. |
800 |
|
* It shouldn't be called manually. |
801 |
|
* |
802 |
|
* @return INPUTtag of type hidden |
803 |
|
*/ |
804 |
|
function get_confirm_element() { |
805 |
|
$values = $this->get_value(); |
806 |
|
$name = $this->get_element_name(); |
807 |
|
|
808 |
|
if (is_array($values)) { |
809 |
|
$c = container(); |
810 |
|
foreach ( $values as $value ) { |
811 |
|
$c->add( form_hidden($name, $value ) ); |
812 |
|
} |
813 |
|
return $c; |
814 |
|
} else { |
815 |
|
return form_hidden($name, $this->get_value() ); |
816 |
|
} |
817 |
|
} |
818 |
|
|
819 |
} // FormElement |
} // FormElement |
820 |
?> |
?> |