/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/form/FormContent.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/form/FormContent.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jonen, Sat Feb 22 21:07:40 2003 UTC revision 1.4 by jonen, Thu Aug 11 14:09:26 2005 UTC
# Line 4  Line 4 
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 Markossian <suren@cbestwhat?>   * @author Suren Markossian <suren@cbestwhat?>
9   * @package phpHtmlLib   * @package phpHtmlLib
10   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 21  require_once($phphtmllib."/form/FormProc Line 21  require_once($phphtmllib."/form/FormProc
21  /**  /**
22   * This class is used to build and render the form.   * This class is used to build and render the form.
23   * It builds a form by creating FormElement objects   * It builds a form by creating FormElement objects
24   * which have automatic validation.  It leaves the   * which have automatic validation.  It leaves the
25   * layout of the form up to the child class.  It has   * layout of the form up to the child class.  It has
26   * a mechanism in place to automagically show a   * a mechanism in place to automagically show a
27   * confirmation 'page' after the data has been submitted   * confirmation 'page' after the data has been submitted
28   * and validated.  It also provides a hook for any   * and validated.  It also provides a hook for any
29   * 'back end' validation of data.  Finally, it provides   * 'back end' validation of data.  Finally, it provides
30   * a function for handling the action of the form, which   * a function for handling the action of the form, which
31   * only gets call after ALL validation has passed.   * only gets call after ALL validation has passed.
# Line 36  require_once($phphtmllib."/form/FormProc Line 36  require_once($phphtmllib."/form/FormProc
36   *   build the FormElement objects that will be used   *   build the FormElement objects that will be used
37   *   by the form.  This function is called EVERY time   *   by the form.  This function is called EVERY time
38   *   the FormContent class is instantiated.  After you   *   the FormContent class is instantiated.  After you
39   *   create the FormElement, you call the   *   create the FormElement, you call the
40   *   FormContent::add_element() method, to add the   *   FormContent::add_element() method, to add the
41   *   FormElement object to the form.  You will then   *   FormElement object to the form.  You will then
42   *   call the 2 methods FormContent::element_label() and   *   call the 2 methods FormContent::element_label() and
43   *   FormContent::element_form() to get access to the   *   FormContent::element_form() to get access to the
# Line 60  require_once($phphtmllib."/form/FormProc Line 60  require_once($phphtmllib."/form/FormProc
60   *   *
61   *   *
62   * form_backend_validation() - This method enables you to   * form_backend_validation() - This method enables you to
63   *   do any "back end" validation of data.  Such as, check   *   do any "back end" validation of data.  Such as, check
64   *   for a duplicate in the DB on a create/new form.  This   *   for a duplicate in the DB on a create/new form.  This
65   *   is called after the FormElement's validation methods have   *   is called after the FormElement's validation methods have
66   *   passed.   *   passed.
67   *   *
68   * form_action() - This method is called after ALL validation   * form_action() - This method is called after ALL validation
69   *   was successfull, including each FormElement object's   *   was successfull, including each FormElement object's
70   *   validation methods, as well as the FormContent::form_backend_validation()   *   validation methods, as well as the FormContent::form_backend_validation()
71   *     *
72   *   *
73   *   *
74   * @package phpHtmlLib   * @package phpHtmlLib
# Line 128  class FormContent { Line 128  class FormContent {
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
# Line 156  class FormContent { Line 170  class FormContent {
170       */       */
171      var $_required_field_marker = "*";      var $_required_field_marker = "*";
172    
173        /**
174         * The form Element's flag to add the :
175         * character at the end of the label.
176         */
177        var $_label_colon_flag = FALSE;
178    
179        /**
180         * This holds how many actions we have
181         * for this form content
182         */
183        var $_action_counter = 0;
184    
185        /**
186         * Automatically strip slashes from
187         * form values?
188         */
189        var $_stripslashes = FALSE;
190    
191        /**
192         * Flag to mark this as having a
193         * File Form Element (child of FEFile)
194         */
195        var $_has_file_element = FALSE;
196    
197        /**
198         * index names of all of the file
199         * form elements (if any).
200         */
201        var $_file_elements = array();
202    
203    
204        /**
205         * The onsubmit value for the form
206         * tag.  FormElement childs can
207         * automatically add to this
208         * by implementing the
209         * form_tag_onsubmit() method
210         */
211        var $_form_on_submit = '';
212        
213        /**
214         * The onsubmit value for the form
215         * tag. This is used by form action
216         * elements to add disable on submit    
217         */
218        var $_form_action_elements_on_submit = '';
219    
220        /**
221         * This is the FormValidation object
222         * used to validate the form elements
223         */
224        var $_FormValidation = NULL;
225    
226    
227            /**
228             * Indicates this entire FormContent
229             * is in readonly mode.  This forces
230             * all of the FormElement to be in
231             * readonly mode.
232             *
233             */
234            var $_is_readonly = FALSE;
235    
236    
237      function FormContent($width="100%", $cancel_action=NULL) {      function FormContent($width="100%", $cancel_action=NULL) {
# Line 208  class FormContent { Line 284  class FormContent {
284      }      }
285    
286      /**      /**
287       * This method allows this class to do any       * This method lets you provide any javascript
288         * that is associated with the form content.
289         * The FormProcessor will automatically call
290         * this and wrap it in a script tag.
291         *
292         * @return string - raw js.
293         */
294        function javascript() {
295            return NULL;
296        }
297    
298        /**
299         * This method allows this class to do any
300       * data munging prior to the form_confirm       * data munging prior to the form_confirm
301       * method being called @ render time.       * method being called @ render time.
302       *       *
# Line 218  class FormContent { Line 306  class FormContent {
306      function pre_confirm() {      function pre_confirm() {
307          return TRUE;          return TRUE;
308      }      }
309        
310            /**
311         * This is a 'hidden' version of pre_confirm
312         * to allow calling the form elements pre_confirm
313         * methods.  This is needed for forms that have
314         * a confirmation requirement and has file inputs.
315         * If the file input FormElement doesn't save off
316         * the uploaded file, then the confirmation page
317         * will not get the file. apache may nuke the temp
318         * file in /tmp.
319         *
320         */
321        function _pre_confirm() {
322            foreach( $this->_file_elements as $name ) {
323                $this->_elements[$name]->_pre_confirm();
324            }
325        }
326    
327    
328          /**          /**
329           * This function is used to show an intermediary           * This function is used to show an intermediary
# Line 233  class FormContent { Line 337  class FormContent {
337           * have to do is show the data, and a confirm           * have to do is show the data, and a confirm
338           * submit button.           * submit button.
339           *           *
340         * @param string - the title for the table
341         * @param boolean - show the action buttons?
342           * @return mixed - either raw html, or some           * @return mixed - either raw html, or some
343           *                 container HTMLTag object.           *                 container HTMLTag object.
344           */           */
345          function form_confirm( ) {          function form_confirm( $title = "Form Confirmation", $show_buttons=TRUE ) {
346          $table = new InfoTable("Form Confirmation", $this->_width);          $table = new InfoTable($title, $this->_width);
347    
348          $this->build_confirm_table( $table );          $this->build_confirm_table( $table );
349    
# Line 251  class FormContent { Line 357  class FormContent {
357              $td->add(_HTML_SPACE, $this->add_cancel());              $td->add(_HTML_SPACE, $this->add_cancel());
358          }          }
359    
360          $table->add_row( $td );          if ($show_buttons) {
361                $table->add_row( $td );
362            }
363    
364          return $table;          return $table;
365          }          }
# Line 267  class FormContent { Line 375  class FormContent {
375       */       */
376      function build_confirm_table( &$table ) {      function build_confirm_table( &$table ) {
377          foreach( $this->_elements as $label => $element) {          foreach( $this->_elements as $label => $element) {
378              $c = container(_HTML_SPACE);              $c = container(_HTML_SPACE, $element->get_value_text());
379              $c->set_collapse();              $c->set_collapse();
380              $value = $element->get_value();              $div = html_div("", $element->get_label($this) );
             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));  
                 }                  
             }  
             $div = html_div("", $element->get_label() );  
381              $div->set_style("white-space:nowrap;");              $div->set_style("white-space:nowrap;");
382              $table->add_row( $div, $c);              $table->add_row( $div, $c);
383          }          }
# Line 296  class FormContent { Line 388  class FormContent {
388       * have all been validated, and the form_confirm       * have all been validated, and the form_confirm
389       * has been confirmed.  It enables the form to       * has been confirmed.  It enables the form to
390       * validate any data against a DB or other backend       * validate any data against a DB or other backend
391       * processing.  This will always get called       * processing.  This will always get called
392       * before the form_action method is called to ensure       * before the form_action method is called to ensure
393       * that all form data is valid before form_action()       * that all form data is valid before form_action()
394       * is called.       * is called.
# Line 348  class FormContent { Line 440  class FormContent {
440       * @return mixed       * @return mixed
441       */       */
442      function form_success() {      function form_success() {
443          return container($this->_action_message, html_br(2));          if ($this->_action_message != "") {
444                return container($this->_action_message, html_br(2));
445            } else {
446                return NULL;
447            }
448      }      }
449    
450          /**          /**
# Line 361  class FormContent { Line 457  class FormContent {
457           * @return TABLEtag object.           * @return TABLEtag object.
458           */           */
459          function form_errors() {          function form_errors() {
460          $table = new InfoTable("Form Errors", $this->_width);          $table = new ErrorBoxWidget($this->_form_errors_title,
461                                                                            $this->get_form_errors_width());
462          $errors = FALSE;          $errors = FALSE;
463    
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                                    $e_errors = $element->get_errors();
468                                    foreach( $e_errors as $err ) {
469                                            $table->add($err['label'], $err['message']);
470                                    }
471                                    $errors = TRUE;
472                            }
473                    }
474                    if ($errors) {
475                            return $table;
476                    } else {
477                            return NULL;
478                    }
479            }
480    
481    
482        /**
483         * This method returns an array of errors
484         * for all the errors.
485         *
486         * @return array
487         */
488        function get_error_array() {
489            $ret = array();
490          //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
491          foreach( $this->_elements as $label => $element ) {          foreach( $this->_elements as $label => $element ) {
492              if ($element->has_error()) {              if ($element->has_error()) {
493                  $span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"),                  $errors = $element->get_errors();
494                                       $label );                  foreach ( $errors as $err ) {
495                  $table->add_row($span, $element->get_error_message());                      $ret[$err['label']] = $err['message'];
496                  $errors = TRUE;                  }
497              }              }
498          }          }
499          if ($errors) {          return $ret;
500              return $table;      }
         } else {  
             return NULL;  
         }    
         }  
501    
502    
503      /*****************************/      /*****************************/
# Line 392  class FormContent { Line 511  class FormContent {
511       * @param FormElement object       * @param FormElement object
512       */       */
513      function add_element( &$element ) {      function add_element( &$element ) {
514          $this->_elements[$element->get_label_text()] = &$element;          $element->set_stripslashes( $this->_stripslashes );
515            //in case the element needs it for js
516            $element->set_form_name( $this->_form_name );
517            $name = $element->get_label_text();
518            $this->_elements[$name] = &$element;
519    
520            //do we have a File form element?
521            if (is_a($element, 'fefile')) {
522                $this->_has_file_element = TRUE;
523                $this->_file_elements[] = $name;
524            }
525            if ($element->_has_form_on_submit) {
526                $this->_form_on_submit .= $element->form_tag_onsubmit();
527            }
528    
529            if ($this->_label_colon_flag) {
530                $element->set_colon_flag(TRUE);            
531            }
532      }      }
533    
534      /**      /**
# Line 403  class FormContent { Line 539  class FormContent {
539       */       */
540      function add_hidden_element( $label, $value=NULL ) {      function add_hidden_element( $label, $value=NULL ) {
541          $element = new FEHidden( $label, $value );          $element = new FEHidden( $label, $value );
542            $element->set_stripslashes( $this->_stripslashes );
543            $element->set_form_name( $this->_form_name );
544          $this->_hidden_elements[$label] = &$element;          $this->_hidden_elements[$label] = &$element;
545      }      }
546        
547            /**
548             * This function adds a form submit button
549             * with the appropriate action.
550             *
551             * @param string - the labe/action for the submit
552             *                 button.
553             * @param bool disable the button
554         * @param string - the onSubmit function (if any)
555         * @param boolean - disable opon submit?
556             * @return INPUTtag object
557             */
558            function add_action_element($label, $disabled = false, $submit_function = false,
559                                    $disable_on_submit = TRUE) {
560    
561            $style="vertical-align:middle;";
562                    // here we mantain a fixed button size if a label length is reasonably small
563                    // i.e. OK or Cancel buttons or use padding otherwise
564                    if (strlen($label)<8)   $style .= "width:100px;";
565                    else $style     .= "padding-left:5px;padding-right:5px;";
566                    
567                    $button_name = FORM_ACTION . $this->_action_counter++;
568                    $button_id = $this->_form_name . "action_" . $button_name;
569    
570            $attributes = array("id" => $button_id,
571                                "onclick" =>"this.form." . FORM_ACTION . ".value='".$label."';",
572                                "style" => $style);
573    
574            if ($disabled) $attributes[] = "disabled";
575    
576            $this->_action_elements[$label] = form_submit($button_name, $label, $attributes);
577    
578            if ($disable_on_submit) {
579                $this->_form_action_elements_on_submit .= "if (document.getElementById('" . $button_id . "')) document.getElementById('" . $button_id . "').disabled=true;";
580            }
581            }
582            
583            /**
584             * This function returns a submit action
585             * by label
586             *
587             * @param string label
588             *
589             * @return object
590             */
591            function get_action_element($label) {
592                return $this->_action_elements[$label];
593            }    
594    
595      /**      /**
596       * This method returns the label object       * This method returns the label object
# Line 414  class FormContent { Line 600  class FormContent {
600       * @return Object       * @return Object
601       */       */
602      function element_label($label) {      function element_label($label) {
603          return $this->_elements[$label]->get_label();          $this->_test_element($label, "element_label");
604            return $this->_elements[$label]->get_label($this);
605        }
606    
607        /**
608         * This method returns the label object
609         * for a visible form element.
610         *
611         * @param string - the element's label
612         * @return Object
613         */
614        function hidden_element_label($label) {
615            $this->_test_element($label, "element_label", TRUE);
616            return $this->_hidden_elements[$label]->get_label($this);
617      }      }
618    
619      /**      /**
# Line 426  class FormContent { Line 625  class FormContent {
625       * @return Object       * @return Object
626       */       */
627      function element_form($label) {      function element_form($label) {
628          return $this->_elements[$label]->get_element();          $this->_test_element($label, "element_form");
629            return $this->_elements[$label]->get_form_element($this->is_readonly());
630      }      }
631    
632      /**      /**
# Line 437  class FormContent { Line 637  class FormContent {
637       * @return Object       * @return Object
638       */       */
639      function &get_element($label) {      function &get_element($label) {
640            $this->_test_element($label, "get_element");
641          return $this->_elements[$label];          return $this->_elements[$label];
642      }      }
643    
# Line 449  class FormContent { Line 650  class FormContent {
650       * @param value - the new value       * @param value - the new value
651       */       */
652      function set_element_value($label, $value) {      function set_element_value($label, $value) {
653            $this->_test_element($label, "set_element_value");
654          $this->_elements[$label]->set_value($value);          $this->_elements[$label]->set_value($value);
655      }      }
656    
# Line 461  class FormContent { Line 663  class FormContent {
663       * @return value - the new value       * @return value - the new value
664       */       */
665      function get_element_value($label) {      function get_element_value($label) {
666            $this->_test_element($label, "get_element_value");
667          return $this->_elements[$label]->get_value();          return $this->_elements[$label]->get_value();
668      }      }
669    
# Line 472  class FormContent { Line 675  class FormContent {
675       * @param value - the new value       * @param value - the new value
676       */       */
677      function set_hidden_element_value($label, $value) {      function set_hidden_element_value($label, $value) {
678            $this->_test_element($label, "set_hidden_element_value", TRUE);
679          $this->_hidden_elements[$label]->set_value( $value );          $this->_hidden_elements[$label]->set_value( $value );
680      }      }
681    
# Line 483  class FormContent { Line 687  class FormContent {
687       * @return value - the new value       * @return value - the new value
688       */       */
689      function get_hidden_element_value($label) {      function get_hidden_element_value($label) {
690            $this->_test_element($label, "get_hidden_element_value", TRUE);
691          return $this->_hidden_elements[$label]->get_value();          return $this->_hidden_elements[$label]->get_value();
692      }      }
693    
694        /**
695         * This method is a helper method to set the
696         * FormElement's tabindex.
697         *
698         * @param string - the form label
699         * @param int - the FormElement's tabindex
700         * @return none
701         */
702        function set_form_tabindex($label, $index) {
703            $this->_test_element($label, "set_form_tabindex");
704            $this->_elements[$label]->set_tabindex($index);
705        }
706    
707        /**
708         * This method is a helper method to get the
709         * FormElement's tabindex.
710         *
711         * @param string - the form label
712         * @param int - the FormElement's tabindex
713         * @return the FormElement's current tabindex
714         */
715        function get_form_tabindex($label, $index) {
716            $this->_test_element($label, "set_form_tabindex");
717            return $this->_elements[$label]->get_tabindex();
718        }
719    
720        /**
721         * This method is used to test
722         * if the element exists in a form
723         *
724         * @param string - the form label
725         * @return bool
726         */
727        function element_exists($label) {
728            return (isset($this->_elements[$label]) || isset($this->_hidden_elements[$label]));
729        }
730    
731      /**      /**
732       * This method is used to create a new error element       * This method is used to create a new error element
733       * during the call to form_action().  This enables us       * during the call to form_action().  This enables us
734       * to do error handling during a transaction into       * to do error handling during a transaction into
735       * a DB.       * a DB.
736       *       *
737       * @param string - the label       * @param string - the label
# Line 501  class FormContent { Line 742  class FormContent {
742              $this->_elements[$label]->set_error_message($message);              $this->_elements[$label]->set_error_message($message);
743          } else {          } else {
744              $this->add_element( new FEError($label, $message) );              $this->add_element( new FEError($label, $message) );
745          }                  }
746      }      }
747    
748    
749            /**
750             * This sets the readonly flag.
751             * When this flag is set, all of the
752             * FormElements will be set to readonly.
753             *
754             * @param bool TRUE = readonly
755             */
756            function set_readonly($flag=TRUE) {
757                    $this->_is_readonly = $flag;
758            }
759    
760            /**
761             * Is this element in read only mode?
762             *
763             * @return bool
764             */
765            function is_readonly() {
766                    return $this->_is_readonly;
767            }
768    
769    
770      /*****************************/      /*****************************/
771      /*       Util methods        */      /*       Util methods        */
772      /*****************************/      /*****************************/
# Line 513  class FormContent { Line 775  class FormContent {
775          $this->_form_name = $name;          $this->_form_name = $name;
776      }      }
777    
778            function get_form_name() {
779                    return $this->_form_name;
780            }
781    
782    
783          /**          /**
784           * Save the action for the form           * Save the action for the form
# Line 539  class FormContent { Line 805  class FormContent {
805       * @param string - the form name       * @param string - the form name
806       */       */
807      function set_form_width($width) {      function set_form_width($width) {
808          $this->_form_width = $width;          $this->_width = $width;
809      }      }
810    
811    
812        /**
813         * This method returns the width
814         * of the form errors table.
815         * By default it is supposed to be
816         * the same width as the form itself.
817         *
818         * @return int
819         */
820        function get_form_errors_width() {
821            if ($this->_form_errors_width == null) {
822                return $this->_width;
823            } else {
824                return $this->_form_errors_width;
825            }
826        }
827    
828        /**
829         * This method allows you to override
830         * the width of the form errors table.
831         * By default it uses the width of the
832         * form as its size.
833         *
834         * @param string - the width
835         */
836        function set_form_errors_width($width) {
837            $this->_form_errors_width = $width;
838        }
839    
840    
841        /**
842         * This allows us to change the form errors
843         * table title
844         *
845         * @param string - the new title
846         */
847        function set_form_errors_title($title) {
848            $this->_form_errors_title = $title;
849        }
850    
851    
852    
853    
854          /**          /**
855           * This function is used to set the           * This function is used to set the
856           * default CSS class used on           * default CSS class used on
# Line 620  class FormContent { Line 928  class FormContent {
928      /**      /**
929       * This sets the action message.       * This sets the action message.
930       * This is called from withint the       * This is called from withint the
931       * form_action() method       * form_action() method
932       *       *
933       * @param string - the action message       * @param string - the action message
934       */       */
# Line 631  class FormContent { Line 939  class FormContent {
939    
940      /**      /**
941       * This method sets the javasript action       * This method sets the javasript action
942       * to be taken when the cancel button       * to be taken when the cancel button
943       * is clicked.  Calling this method       * is clicked.  Calling this method
944       * w/ a non NULL value automatically enables       * w/ a non NULL value automatically enables
945       * the Cancel button.       * the Cancel button.
# Line 642  class FormContent { Line 950  class FormContent {
950          $this->_cancel_action = $action;          $this->_cancel_action = $action;
951      }      }
952    
953        /**
954         * This method sets the flag to have ALL of the
955         * FormElement's labels be appended with a :
956         * character.  Some folks like this for some
957         * completely unexplained reason.
958         */
959        function set_colon_flag($flag=TRUE) {
960            $this->_label_colon_flag = $flag;
961        }
962    
963    
964    
# Line 672  class FormContent { Line 988  class FormContent {
988          $blabel = FORM_ACTION.$this->_action_counter;          $blabel = FORM_ACTION.$this->_action_counter;
989          $this->_action_counter++;          $this->_action_counter++;
990    
991          // The onClick is responsible for:          // The onclick is responsible for:
992          // -disabling the action button to discourage stupid users          // -disabling the action button to discourage stupid users
993          // -setting the action in the _form_action hidden variable          // -setting the action in the _form_action hidden variable
994          // -calling the onSubmit function (if any), since form.submit() will not trigger          // -calling the onSubmit function (if any), since form.submit() will not trigger
# Line 688  class FormContent { Line 1004  class FormContent {
1004          if ($submit_function) {          if ($submit_function) {
1005              $onclick .= $submit_function.";";              $onclick .= $submit_function.";";
1006          }          }
1007          $onclick .= "this.form.submit();";  
1008            if ($disable_on_submit) {
1009                $onclick .= "this.form.submit();";
1010            }
1011    
1012          $attrib = array("style" => $style,          $attrib = array("style" => $style,
1013                          "onClick" => $onclick);                          "onclick" => $onclick);
1014    
1015          if ($disabled) $attrib[] = "disabled";          if ($disabled) $attrib[] = "disabled";
1016          return form_submit($blabel, $label, $attrib);          return form_submit($blabel, $label, $attrib);
# Line 728  class FormContent { Line 1047  class FormContent {
1047    
1048          $style = "padding-left: 5px;padding-right:5px;";          $style = "padding-left: 5px;padding-right:5px;";
1049          $attrib = array("style" => $style,          $attrib = array("style" => $style,
1050                          "onClick" => $onclick);                          "onclick" => $onclick);
1051    
1052          $container->push(form_submit($blabel, $label,          $container->push(form_submit($blabel, $label,
1053                                       array("style" => $style,                                       array("style" => $style,
1054                                             "onClick" => $onclick)));                                             "onclick" => $onclick)));
1055          return $container;          return $container;
1056          }          }
1057    
# Line 744  class FormContent { Line 1063  class FormContent {
1063           * @param string - the action           * @param string - the action
1064       * @param boolean - disable opon submit?       * @param boolean - disable opon submit?
1065           *           *
1066           * @return           * @return Atag object
1067           */           */
1068          function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) {          function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) {
1069                  $container = container();                  // Unique button label
   
         $container = new ContainerWidget;  
         // Unique button label  
1070          if (!$this->_action_counter) {          if (!$this->_action_counter) {
1071              $this->_action_counter = 1;              $this->_action_counter = 1;
1072          }          }
1073          $blabel = FORM_ACTION.$this->_action_counter;          $blabel = "_form_action".$this->_action_counter;
1074          $this->_action_counter++;          $this->_action_counter++;
1075    
1076          $img = form_image($blabel, $action, $image_name);          $onclick = "document.".$this->_form_name."._form_action.value='".$action."';";
1077          //NS 4 hack          $onclick .= "document.".$this->_form_name.".submit();";
1078          $img->set_tag_attribute("border", 0 );  
         $img->set_tag_attribute("style", "cursor:hand;");  
         //build the action  
         $onclick = "";  
1079          if ($disable_on_submit) {          if ($disable_on_submit) {
1080              $onclick .= "this.form.".$blabel.".disabled=true;";              $click = "javascript:if (!window.global_cntr) {window.global_cntr = 1;} else {window.global_cntr++;} ";
1081                $click .= " if(window.global_cntr<2) {";
1082                $click .= $onclick."}";
1083          }          }
         $onclick .= "this.form.".FORM_ACTION.".value='".$action."';";  
         $onclick .= "this.form.submit();";  
1084    
1085          $img->set_tag_attribute("onClick", $onclick);          $img = html_img($image_name);
1086          //IE HACK          $img->set_tag_attribute("border", 0 );
1087          $container->push($img);          $img->set_tag_attribute("style", "cursor:hand;");
1088    
1089          return $container;          $link = html_a("#", $img);
1090            $link->set_tag_attribute("onclick", $click);
1091            return $link;
1092          }          }
1093    
1094    
1095      /**      /**
1096       * build a cancel button with a url       * build a cancel button with a url
1097       * to go to       * to go to
1098       *       *
1099       * @param string - the cancel action       * @param string - the cancel action
1100       * @return form button       * @return form button
1101       */       */
1102      function add_cancel() {      function add_cancel() {
# Line 789  class FormContent { Line 1104  class FormContent {
1104          $cancel_button = form_button("cancel","Cancel",          $cancel_button = form_button("cancel","Cancel",
1105                                       array("type"=>"button",                                       array("type"=>"button",
1106                                             "style"=>"width: 90px;",                                             "style"=>"width: 90px;",
1107                                             "onClick"=>                                             "onclick"=>
1108                                             "javascript:document.location='".$this->_cancel_action."'"));                                             "javascript:document.location='".$this->_cancel_action."'"));
1109          $cancel_button->set_style("vertical-align:middle");          $cancel_button->set_style("vertical-align:middle");
1110          return $cancel_button;          return $cancel_button;
1111      }      }
1112    
1113        /**
1114         * This function is used to set the required field marker
1115         *
1116         * @param string - the marker
1117         */
1118         function set_required_marker($marker) {
1119             $this->_required_field_marker = $marker;
1120         }
1121    
1122          /**      /**
1123           * This returns the required field text       * This function is used to get the required field marker
1124           * if there are any.  otherwise it returns NULL       *
1125           *       * @return string - the marker
1126           */       */
1127          function get_required_fields_text() {       function get_required_marker() {
1128                  if ( count($this->required_fields) ) {           if (is_object($this->_required_field_marker)) {
1129                 return $this->_required_field_marker->render();
1130             } else {
1131                 return $this->_required_field_marker;
1132             }
1133         }
1134    
1135                          $span = new SPANtag( array( "class" => "formlabel"),       /**
1136                                                                   $this->_required_field_marker.        * This sets the required text
1137                                                                   $this->required_field_text, FALSE );        *
1138          * @param string
1139          */
1140          function set_required_text($text) {
1141              $this->_required_field_text = $text;
1142    
1143                          return $span;        }
1144                  } else {  
1145                          return "&nbsp;";  
1146                  }      /**
1147          }       * This method tests to see if we
1148         * have an element named $label,
1149         * so we can operate on it.
1150         *
1151         * @param string - the element's label
1152         * @param string - the name of the method that called us
1153         * @param boolean - test a hidden element?
1154         */
1155        function _test_element( $label, $method, $hidden=FALSE ) {
1156            if ($hidden) {
1157                if (!isset($this->_hidden_elements[$label])) {
1158                    trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR);
1159                }
1160            } else {
1161                if (!isset($this->_elements[$label])) {
1162                    trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR);
1163                }
1164            }
1165        }
1166    
1167        /**
1168         * return the values of all visible form elements as an array
1169         *
1170         * @access public
1171         * @return array
1172         *
1173         */
1174        function get_all_element_values()
1175        {
1176    
1177            foreach ($this->_elements as $element) {
1178                $data[$element->get_element_name()] = $element->get_value();
1179            }
1180    
1181            return $data;
1182    
1183        }
1184    
1185        /**
1186         * This method is used to keep a local reference
1187         * of the FormProcessor's FormValidation object
1188         *
1189         * @param FormValidation object
1190         */
1191        function _set_validation_object(&$FormValidation) {
1192            $this->_FormValidation =& $FormValidation;
1193        }
1194    
1195  }  }
1196  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed