128 |
*/ |
*/ |
129 |
var $_width = "600"; |
var $_width = "600"; |
130 |
|
|
131 |
|
/** |
132 |
|
* Holds the width (if any) of the errors |
133 |
|
* table that will be rendered. If the |
134 |
|
* value is null, the $this->_width value |
135 |
|
* is used instead. |
136 |
|
*/ |
137 |
|
var $_form_errors_width = null; |
138 |
|
|
139 |
|
|
140 |
|
/** |
141 |
|
* The form errors table title |
142 |
|
*/ |
143 |
|
var $_form_errors_title = "Form Errors"; |
144 |
|
|
145 |
|
|
146 |
/** |
/** |
147 |
* The message that is set |
* The message that is set |
170 |
*/ |
*/ |
171 |
var $_required_field_marker = "*"; |
var $_required_field_marker = "*"; |
172 |
|
|
173 |
|
/** |
174 |
|
* This holds how many actions we have |
175 |
|
* for this form content |
176 |
|
*/ |
177 |
|
var $_action_counter = 0; |
178 |
|
|
179 |
|
/** |
180 |
|
* Automatically strip slashes from |
181 |
|
* form values? |
182 |
|
*/ |
183 |
|
var $_stripslashes = FALSE; |
184 |
|
|
185 |
|
/** |
186 |
|
* Flag to mark this as having a |
187 |
|
* File Form Element (child of FEFile) |
188 |
|
*/ |
189 |
|
var $_has_file_element = FALSE; |
190 |
|
|
191 |
|
/** |
192 |
|
* index names of all of the file |
193 |
|
* form elements (if any). |
194 |
|
*/ |
195 |
|
var $_file_elements = array(); |
196 |
|
|
197 |
|
|
198 |
|
/** |
199 |
|
* The onsubmit value for the form |
200 |
|
* tag. FormElement childs can |
201 |
|
* automatically add to this |
202 |
|
* by implementing the |
203 |
|
* form_tag_onsubmit() method |
204 |
|
*/ |
205 |
|
var $_form_on_submit = ''; |
206 |
|
|
207 |
|
|
208 |
function FormContent($width="100%", $cancel_action=NULL) { |
function FormContent($width="100%", $cancel_action=NULL) { |
255 |
} |
} |
256 |
|
|
257 |
/** |
/** |
258 |
|
* This method lets you provide any javascript |
259 |
|
* that is associated with the form content. |
260 |
|
* The FormProcessor will automatically call |
261 |
|
* this and wrap it in a script tag. |
262 |
|
* |
263 |
|
* @return string - raw js. |
264 |
|
*/ |
265 |
|
function javascript() { |
266 |
|
return NULL; |
267 |
|
} |
268 |
|
|
269 |
|
/** |
270 |
* This method allows this class to do any |
* This method allows this class to do any |
271 |
* data munging prior to the form_confirm |
* data munging prior to the form_confirm |
272 |
* method being called @ render time. |
* method being called @ render time. |
277 |
function pre_confirm() { |
function pre_confirm() { |
278 |
return TRUE; |
return TRUE; |
279 |
} |
} |
280 |
|
|
281 |
|
/** |
282 |
|
* This is a 'hidden' version of pre_confirm |
283 |
|
* to allow calling the form elements pre_confirm |
284 |
|
* methods. This is needed for forms that have |
285 |
|
* a confirmation requirement and has file inputs. |
286 |
|
* If the file input FormElement doesn't save off |
287 |
|
* the uploaded file, then the confirmation page |
288 |
|
* will not get the file. apache may nuke the temp |
289 |
|
* file in /tmp. |
290 |
|
* |
291 |
|
*/ |
292 |
|
function _pre_confirm() { |
293 |
|
foreach( $this->_file_elements as $name ) { |
294 |
|
$this->_elements[$name]->_pre_confirm(); |
295 |
|
} |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
/** |
/** |
308 |
* have to do is show the data, and a confirm |
* have to do is show the data, and a confirm |
309 |
* submit button. |
* submit button. |
310 |
* |
* |
311 |
|
* @param string - the title for the table |
312 |
|
* @param boolean - show the action buttons? |
313 |
* @return mixed - either raw html, or some |
* @return mixed - either raw html, or some |
314 |
* container HTMLTag object. |
* container HTMLTag object. |
315 |
*/ |
*/ |
316 |
function form_confirm( ) { |
function form_confirm( $title = "Form Confirmation", $show_buttons=TRUE ) { |
317 |
$table = new InfoTable("Form Confirmation", $this->_width); |
$table = new InfoTable($title, $this->_width); |
318 |
|
|
319 |
$this->build_confirm_table( $table ); |
$this->build_confirm_table( $table ); |
320 |
|
|
328 |
$td->add(_HTML_SPACE, $this->add_cancel()); |
$td->add(_HTML_SPACE, $this->add_cancel()); |
329 |
} |
} |
330 |
|
|
331 |
$table->add_row( $td ); |
if ($show_buttons) { |
332 |
|
$table->add_row( $td ); |
333 |
|
} |
334 |
|
|
335 |
return $table; |
return $table; |
336 |
} |
} |
346 |
*/ |
*/ |
347 |
function build_confirm_table( &$table ) { |
function build_confirm_table( &$table ) { |
348 |
foreach( $this->_elements as $label => $element) { |
foreach( $this->_elements as $label => $element) { |
349 |
$c = container(_HTML_SPACE); |
$c = container(_HTML_SPACE,_HTML_SPACE, |
350 |
|
$element->get_value_text()); |
351 |
$c->set_collapse(); |
$c->set_collapse(); |
|
$value = $element->get_value(); |
|
|
if (is_array($value)) { |
|
|
$str = ''; |
|
|
foreach($value as $item) { |
|
|
$str .= $element->get_value_text($item).","; |
|
|
} |
|
|
$str = substr($str,0,strlen($str)-1); |
|
|
$c->add( _HTML_SPACE, $str ); |
|
|
} else { |
|
|
if (is_a($element, "FEPassword")) { |
|
|
$value = str_repeat('*', strlen($value)); |
|
|
$c->add(_HTML_SPACE, $value); |
|
|
} else { |
|
|
$c->add(_HTML_SPACE, $element->get_value_text($value)); |
|
|
} |
|
|
} |
|
352 |
$div = html_div("", $element->get_label() ); |
$div = html_div("", $element->get_label() ); |
353 |
$div->set_style("white-space:nowrap;"); |
$div->set_style("white-space:nowrap;"); |
354 |
$table->add_row( $div, $c); |
$table->add_row( $div, $c); |
412 |
* @return mixed |
* @return mixed |
413 |
*/ |
*/ |
414 |
function form_success() { |
function form_success() { |
415 |
return container($this->_action_message, html_br(2)); |
if ($this->_action_message != "") { |
416 |
|
return container($this->_action_message, html_br(2)); |
417 |
|
} else { |
418 |
|
return NULL; |
419 |
|
} |
420 |
} |
} |
421 |
|
|
422 |
/** |
/** |
429 |
* @return TABLEtag object. |
* @return TABLEtag object. |
430 |
*/ |
*/ |
431 |
function form_errors() { |
function form_errors() { |
432 |
$table = new InfoTable("Form Errors", $this->_width); |
$table = new InfoTable($this->_form_errors_title, $this->get_form_errors_width()); |
433 |
$errors = FALSE; |
$errors = FALSE; |
434 |
|
|
435 |
//walk each visible form element and see if there is an error in it |
//walk each visible form element and see if there is an error in it |
436 |
foreach( $this->_elements as $label => $element ) { |
foreach( $this->_elements as $label => $element ) { |
437 |
if ($element->has_error()) { |
if ($element->has_error()) { |
438 |
$span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"), |
$e_errors = $element->get_errors(); |
439 |
$label ); |
foreach( $e_errors as $err ) { |
440 |
$table->add_row($span, $element->get_error_message()); |
$span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"), |
441 |
|
$err['label'] ); |
442 |
|
$table->add_row($span, $err['message']); |
443 |
|
} |
444 |
|
|
445 |
$errors = TRUE; |
$errors = TRUE; |
446 |
} |
} |
447 |
} |
} |
449 |
return $table; |
return $table; |
450 |
} else { |
} else { |
451 |
return NULL; |
return NULL; |
452 |
} |
} |
453 |
} |
} |
454 |
|
|
455 |
|
|
456 |
|
/** |
457 |
|
* This method returns an array of errors |
458 |
|
* for all the errors. |
459 |
|
* |
460 |
|
* @return array |
461 |
|
*/ |
462 |
|
function get_error_array() { |
463 |
|
$ret = array(); |
464 |
|
//walk each visible form element and see if there is an error in it |
465 |
|
foreach( $this->_elements as $label => $element ) { |
466 |
|
if ($element->has_error()) { |
467 |
|
$errors = $element->get_errors(); |
468 |
|
foreach ( $errors as $err ) { |
469 |
|
$ret[$err['label']] = $err['message']; |
470 |
|
} |
471 |
|
} |
472 |
|
} |
473 |
|
return $ret; |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
/*****************************/ |
/*****************************/ |
478 |
/* form element methods */ |
/* form element methods */ |
479 |
/*****************************/ |
/*****************************/ |
485 |
* @param FormElement object |
* @param FormElement object |
486 |
*/ |
*/ |
487 |
function add_element( &$element ) { |
function add_element( &$element ) { |
488 |
$this->_elements[$element->get_label_text()] = &$element; |
$element->set_stripslashes( $this->_stripslashes ); |
489 |
|
//in case the element needs it for js |
490 |
|
$element->set_form_name( $this->_form_name ); |
491 |
|
$name = $element->get_label_text(); |
492 |
|
$this->_elements[$name] = &$element; |
493 |
|
|
494 |
|
//do we have a File form element? |
495 |
|
if (is_a($element, 'fefile')) { |
496 |
|
$this->_has_file_element = TRUE; |
497 |
|
$this->_file_elements[] = $name; |
498 |
|
} |
499 |
|
if ($element->_has_form_on_submit) { |
500 |
|
$this->_form_on_submit .= $element->form_tag_onsubmit(); |
501 |
|
} |
502 |
} |
} |
503 |
|
|
504 |
/** |
/** |
509 |
*/ |
*/ |
510 |
function add_hidden_element( $label, $value=NULL ) { |
function add_hidden_element( $label, $value=NULL ) { |
511 |
$element = new FEHidden( $label, $value ); |
$element = new FEHidden( $label, $value ); |
512 |
|
$element->set_stripslashes( $this->_stripslashes ); |
513 |
$this->_hidden_elements[$label] = &$element; |
$this->_hidden_elements[$label] = &$element; |
514 |
} |
} |
515 |
|
|
521 |
* @return Object |
* @return Object |
522 |
*/ |
*/ |
523 |
function element_label($label) { |
function element_label($label) { |
524 |
return $this->_elements[$label]->get_label(); |
$this->_test_element($label, "element_label"); |
525 |
|
return $this->_elements[$label]->get_label($this); |
526 |
|
} |
527 |
|
|
528 |
|
/** |
529 |
|
* This method returns the label object |
530 |
|
* for a visible form element. |
531 |
|
* |
532 |
|
* @param string - the element's label |
533 |
|
* @return Object |
534 |
|
*/ |
535 |
|
function hidden_element_label($label) { |
536 |
|
$this->_test_element($label, "element_label", TRUE); |
537 |
|
return $this->_hidden_elements[$label]->get_label(); |
538 |
} |
} |
539 |
|
|
540 |
/** |
/** |
546 |
* @return Object |
* @return Object |
547 |
*/ |
*/ |
548 |
function element_form($label) { |
function element_form($label) { |
549 |
|
$this->_test_element($label, "element_form"); |
550 |
return $this->_elements[$label]->get_element(); |
return $this->_elements[$label]->get_element(); |
551 |
} |
} |
552 |
|
|
558 |
* @return Object |
* @return Object |
559 |
*/ |
*/ |
560 |
function &get_element($label) { |
function &get_element($label) { |
561 |
|
$this->_test_element($label, "get_element"); |
562 |
return $this->_elements[$label]; |
return $this->_elements[$label]; |
563 |
} |
} |
564 |
|
|
571 |
* @param value - the new value |
* @param value - the new value |
572 |
*/ |
*/ |
573 |
function set_element_value($label, $value) { |
function set_element_value($label, $value) { |
574 |
|
$this->_test_element($label, "set_element_value"); |
575 |
$this->_elements[$label]->set_value($value); |
$this->_elements[$label]->set_value($value); |
576 |
} |
} |
577 |
|
|
584 |
* @return value - the new value |
* @return value - the new value |
585 |
*/ |
*/ |
586 |
function get_element_value($label) { |
function get_element_value($label) { |
587 |
|
$this->_test_element($label, "get_element_value"); |
588 |
return $this->_elements[$label]->get_value(); |
return $this->_elements[$label]->get_value(); |
589 |
} |
} |
590 |
|
|
596 |
* @param value - the new value |
* @param value - the new value |
597 |
*/ |
*/ |
598 |
function set_hidden_element_value($label, $value) { |
function set_hidden_element_value($label, $value) { |
599 |
|
$this->_test_element($label, "set_hidden_element_value", TRUE); |
600 |
$this->_hidden_elements[$label]->set_value( $value ); |
$this->_hidden_elements[$label]->set_value( $value ); |
601 |
} |
} |
602 |
|
|
608 |
* @return value - the new value |
* @return value - the new value |
609 |
*/ |
*/ |
610 |
function get_hidden_element_value($label) { |
function get_hidden_element_value($label) { |
611 |
|
$this->_test_element($label, "get_hidden_element_value", TRUE); |
612 |
return $this->_hidden_elements[$label]->get_value(); |
return $this->_hidden_elements[$label]->get_value(); |
613 |
} |
} |
614 |
|
|
615 |
|
/** |
616 |
|
* This method is a helper method to set the |
617 |
|
* FormElement's tabindex. |
618 |
|
* |
619 |
|
* @param string - the form label |
620 |
|
* @param int - the FormElement's tabindex |
621 |
|
* @return none |
622 |
|
*/ |
623 |
|
function set_form_tabindex($label, $index) { |
624 |
|
$this->_test_element($label, "set_form_tabindex"); |
625 |
|
$this->_elements[$label]->set_tabindex($index); |
626 |
|
} |
627 |
|
|
628 |
|
/** |
629 |
|
* This method is a helper method to get the |
630 |
|
* FormElement's tabindex. |
631 |
|
* |
632 |
|
* @param string - the form label |
633 |
|
* @param int - the FormElement's tabindex |
634 |
|
* @return the FormElement's current tabindex |
635 |
|
*/ |
636 |
|
function get_form_tabindex($label, $index) { |
637 |
|
$this->_test_element($label, "set_form_tabindex"); |
638 |
|
return $this->_elements[$label]->get_tabindex(); |
639 |
|
} |
640 |
|
|
641 |
|
|
642 |
|
|
643 |
/** |
/** |
644 |
* This method is used to create a new error element |
* This method is used to create a new error element |
692 |
* @param string - the form name |
* @param string - the form name |
693 |
*/ |
*/ |
694 |
function set_form_width($width) { |
function set_form_width($width) { |
695 |
$this->_form_width = $width; |
$this->_width = $width; |
696 |
} |
} |
697 |
|
|
698 |
|
|
699 |
|
/** |
700 |
|
* This method returns the width |
701 |
|
* of the form errors table. |
702 |
|
* By default it is supposed to be |
703 |
|
* the same width as the form itself. |
704 |
|
* |
705 |
|
* @return int |
706 |
|
*/ |
707 |
|
function get_form_errors_width() { |
708 |
|
if ($this->_form_errors_width == null) { |
709 |
|
return $this->_width; |
710 |
|
} else { |
711 |
|
return $this->_form_errors_width; |
712 |
|
} |
713 |
|
} |
714 |
|
|
715 |
|
/** |
716 |
|
* This method allows you to override |
717 |
|
* the width of the form errors table. |
718 |
|
* By default it uses the width of the |
719 |
|
* form as its size. |
720 |
|
* |
721 |
|
* @param string - the width |
722 |
|
*/ |
723 |
|
function set_form_errors_width($width) { |
724 |
|
$this->_form_errors_width = $width; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
/** |
729 |
|
* This allows us to change the form errors |
730 |
|
* table title |
731 |
|
* |
732 |
|
* @param string - the new title |
733 |
|
*/ |
734 |
|
function set_form_errors_title($title) { |
735 |
|
$this->_form_errors_title = $title; |
736 |
|
} |
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
/** |
/** |
742 |
* This function is used to set the |
* This function is used to set the |
743 |
* default CSS class used on |
* default CSS class used on |
939 |
* @param string - the action |
* @param string - the action |
940 |
* @param boolean - disable opon submit? |
* @param boolean - disable opon submit? |
941 |
* |
* |
942 |
* @return |
* @return Atag object |
943 |
*/ |
*/ |
944 |
function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) { |
function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) { |
945 |
$container = container(); |
// Unique button label |
|
|
|
|
$container = new ContainerWidget; |
|
|
// Unique button label |
|
946 |
if (!$this->_action_counter) { |
if (!$this->_action_counter) { |
947 |
$this->_action_counter = 1; |
$this->_action_counter = 1; |
948 |
} |
} |
949 |
$blabel = FORM_ACTION.$this->_action_counter; |
$blabel = "_form_action".$this->_action_counter; |
950 |
$this->_action_counter++; |
$this->_action_counter++; |
951 |
|
|
952 |
$img = form_image($blabel, $action, $image_name); |
$onclick = "document.".$this->_form_name."._form_action.value='".$action."';"; |
953 |
//NS 4 hack |
$onclick .= "document.".$this->_form_name.".submit();"; |
954 |
$img->set_tag_attribute("border", 0 ); |
|
|
$img->set_tag_attribute("style", "cursor:hand;"); |
|
|
//build the action |
|
|
$onclick = ""; |
|
955 |
if ($disable_on_submit) { |
if ($disable_on_submit) { |
956 |
$onclick .= "this.form.".$blabel.".disabled=true;"; |
$click = "javascript:if (!window.global_cntr) {window.global_cntr = 1;} else {window.global_cntr++;} "; |
957 |
|
$click .= " if(window.global_cntr<2) {"; |
958 |
|
$click .= $onclick."}"; |
959 |
} |
} |
960 |
$onclick .= "this.form.".FORM_ACTION.".value='".$action."';"; |
|
961 |
$onclick .= "this.form.submit();"; |
$img = html_img($image_name); |
962 |
|
$img->set_tag_attribute("border", 0 ); |
963 |
$img->set_tag_attribute("onClick", $onclick); |
$img->set_tag_attribute("style", "cursor:hand;"); |
|
//IE HACK |
|
|
$container->push($img); |
|
964 |
|
|
965 |
return $container; |
$link = html_a("#", $img); |
966 |
|
$link->set_tag_attribute("onclick", $click); |
967 |
|
return $link; |
968 |
} |
} |
969 |
|
|
970 |
|
|
985 |
$cancel_button->set_style("vertical-align:middle"); |
$cancel_button->set_style("vertical-align:middle"); |
986 |
return $cancel_button; |
return $cancel_button; |
987 |
} |
} |
988 |
|
|
989 |
|
/** |
990 |
|
* This function is used to set the required field marker |
991 |
|
* |
992 |
|
* @param string - the marker |
993 |
|
*/ |
994 |
|
function set_required_marker($marker) { |
995 |
|
$this->_required_field_marker = $marker; |
996 |
|
} |
997 |
|
|
998 |
|
/** |
999 |
|
* This sets the required text |
1000 |
|
* |
1001 |
|
* @param string |
1002 |
|
*/ |
1003 |
|
function set_required_text($text) { |
1004 |
|
$this->_required_field_text = $text; |
1005 |
|
|
1006 |
|
} |
1007 |
|
|
1008 |
|
|
1009 |
/** |
/** |
1010 |
* This returns the required field text |
* This method tests to see if we |
1011 |
* if there are any. otherwise it returns NULL |
* have an element named $label, |
1012 |
* |
* so we can operate on it. |
1013 |
*/ |
* |
1014 |
function get_required_fields_text() { |
* @param string - the element's label |
1015 |
if ( count($this->required_fields) ) { |
* @param string - the name of the method that called us |
1016 |
|
* @param boolean - test a hidden element? |
1017 |
$span = new SPANtag( array( "class" => "formlabel"), |
*/ |
1018 |
$this->_required_field_marker. |
function _test_element( $label, $method, $hidden=FALSE ) { |
1019 |
$this->required_field_text, FALSE ); |
if ($hidden) { |
1020 |
|
if (!isset($this->_hidden_elements[$label])) { |
1021 |
return $span; |
trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR); |
1022 |
} else { |
} |
1023 |
return " "; |
} else { |
1024 |
} |
if (!isset($this->_elements[$label])) { |
1025 |
} |
trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR); |
1026 |
|
} |
1027 |
|
} |
1028 |
|
} |
1029 |
|
|
1030 |
|
|
1031 |
} |
} |