/[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.2 by jonen, Sat Sep 20 00:18:43 2003 UTC
# 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         * 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    
187      function FormContent($width="100%", $cancel_action=NULL) {      function FormContent($width="100%", $cancel_action=NULL) {
# Line 208  class FormContent { Line 234  class FormContent {
234      }      }
235    
236      /**      /**
237         * This method lets you provide any javascript
238         * that is associated with the form content.
239         * The FormProcessor will automatically call
240         * this and wrap it in a script tag.
241         *
242         * @return string - raw js.
243         */
244        function javascript() {
245            return NULL;
246        }
247    
248        /**
249       * This method allows this class to do any       * This method allows this class to do any
250       * data munging prior to the form_confirm       * data munging prior to the form_confirm
251       * method being called @ render time.       * method being called @ render time.
# Line 233  class FormContent { Line 271  class FormContent {
271           * have to do is show the data, and a confirm           * have to do is show the data, and a confirm
272           * submit button.           * submit button.
273           *           *
274         * @param string - the title for the table
275         * @param boolean - show the action buttons?
276           * @return mixed - either raw html, or some           * @return mixed - either raw html, or some
277           *                 container HTMLTag object.           *                 container HTMLTag object.    
278           */           */
279          function form_confirm( ) {          function form_confirm( $title = "Form Confirmation", $show_buttons=TRUE ) {
280          $table = new InfoTable("Form Confirmation", $this->_width);          $table = new InfoTable($title, $this->_width);
281    
282          $this->build_confirm_table( $table );          $this->build_confirm_table( $table );
283    
# Line 251  class FormContent { Line 291  class FormContent {
291              $td->add(_HTML_SPACE, $this->add_cancel());              $td->add(_HTML_SPACE, $this->add_cancel());
292          }          }
293    
294          $table->add_row( $td );          if ($show_buttons) {
295                $table->add_row( $td );
296            }
297    
298          return $table;          return $table;
299          }          }
# Line 361  class FormContent { Line 403  class FormContent {
403           * @return TABLEtag object.           * @return TABLEtag object.
404           */           */
405          function form_errors() {          function form_errors() {
406          $table = new InfoTable("Form Errors", $this->_width);          $table = new InfoTable($this->_form_errors_title, $this->get_form_errors_width());
407          $errors = FALSE;          $errors = FALSE;
408    
409          //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
410          foreach( $this->_elements as $label => $element ) {          foreach( $this->_elements as $label => $element ) {
411              if ($element->has_error()) {              if ($element->has_error()) {
412                  $span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"),                  $e_errors = $element->get_errors();
413                                       $label );                  foreach( $e_errors as $err ) {
414                  $table->add_row($span, $element->get_error_message());                      $span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"),
415                                             $err['label'] );
416                        $table->add_row($span, $err['message']);
417                    }
418                    
419                  $errors = TRUE;                  $errors = TRUE;
420              }              }
421          }          }
# Line 377  class FormContent { Line 423  class FormContent {
423              return $table;              return $table;
424          } else {          } else {
425              return NULL;              return NULL;
426          }            }
427          }          }
428    
429    
430        /**
431         * This method returns an array of errors
432         * for all the errors.
433         *
434         * @return array
435         */
436        function get_error_array() {
437            $ret = array();
438            //walk each visible form element and see if there is an error in it
439            foreach( $this->_elements as $label => $element ) {
440                if ($element->has_error()) {
441                    $errors = $element->get_errors();
442                    foreach ( $errors as $err ) {
443                        $ret[$err['label']] = $err['message'];
444                    }                
445                }
446            }
447            return $ret;
448        }
449    
450    
451      /*****************************/      /*****************************/
452      /*     form element methods  */      /*     form element methods  */
453      /*****************************/      /*****************************/
# Line 392  class FormContent { Line 459  class FormContent {
459       * @param FormElement object       * @param FormElement object
460       */       */
461      function add_element( &$element ) {      function add_element( &$element ) {
462            $element->set_stripslashes( $this->_stripslashes );
463            //in case the element needs it for js
464            $element->set_form_name( $this->_form_name );
465          $this->_elements[$element->get_label_text()] = &$element;          $this->_elements[$element->get_label_text()] = &$element;
466      }      }
467    
# Line 403  class FormContent { Line 473  class FormContent {
473       */       */
474      function add_hidden_element( $label, $value=NULL ) {      function add_hidden_element( $label, $value=NULL ) {
475          $element = new FEHidden( $label, $value );          $element = new FEHidden( $label, $value );
476            $element->set_stripslashes( $this->_stripslashes );
477          $this->_hidden_elements[$label] = &$element;          $this->_hidden_elements[$label] = &$element;
478      }      }
479    
# Line 414  class FormContent { Line 485  class FormContent {
485       * @return Object       * @return Object
486       */       */
487      function element_label($label) {      function element_label($label) {
488            $this->_test_element($label, "element_label");
489          return $this->_elements[$label]->get_label();          return $this->_elements[$label]->get_label();
490      }      }
491    
492      /**      /**
493         * This method returns the label object
494         * for a visible form element.
495         *
496         * @param string - the element's label
497         * @return Object
498         */
499        function hidden_element_label($label) {
500            $this->_test_element($label, "element_label", TRUE);
501            return $this->_hidden_elements[$label]->get_label();
502        }
503    
504        /**
505       * This method returns the actual form       * This method returns the actual form
506       * object that renders the form field.       * object that renders the form field.
507       * Such as an INPUTtag object.       * Such as an INPUTtag object.
# Line 426  class FormContent { Line 510  class FormContent {
510       * @return Object       * @return Object
511       */       */
512      function element_form($label) {      function element_form($label) {
513            $this->_test_element($label, "element_form");
514          return $this->_elements[$label]->get_element();          return $this->_elements[$label]->get_element();
515      }      }
516    
# Line 437  class FormContent { Line 522  class FormContent {
522       * @return Object       * @return Object
523       */       */
524      function &get_element($label) {      function &get_element($label) {
525            $this->_test_element($label, "get_element");
526          return $this->_elements[$label];          return $this->_elements[$label];
527      }      }
528    
# Line 449  class FormContent { Line 535  class FormContent {
535       * @param value - the new value       * @param value - the new value
536       */       */
537      function set_element_value($label, $value) {      function set_element_value($label, $value) {
538            $this->_test_element($label, "set_element_value");
539          $this->_elements[$label]->set_value($value);          $this->_elements[$label]->set_value($value);
540      }      }
541    
# Line 461  class FormContent { Line 548  class FormContent {
548       * @return value - the new value       * @return value - the new value
549       */       */
550      function get_element_value($label) {      function get_element_value($label) {
551            $this->_test_element($label, "get_element_value");
552          return $this->_elements[$label]->get_value();          return $this->_elements[$label]->get_value();
553      }      }
554    
# Line 472  class FormContent { Line 560  class FormContent {
560       * @param value - the new value       * @param value - the new value
561       */       */
562      function set_hidden_element_value($label, $value) {      function set_hidden_element_value($label, $value) {
563            $this->_test_element($label, "set_hidden_element_value", TRUE);
564          $this->_hidden_elements[$label]->set_value( $value );          $this->_hidden_elements[$label]->set_value( $value );
565      }      }
566    
# Line 483  class FormContent { Line 572  class FormContent {
572       * @return value - the new value       * @return value - the new value
573       */       */
574      function get_hidden_element_value($label) {      function get_hidden_element_value($label) {
575            $this->_test_element($label, "get_hidden_element_value", TRUE);
576          return $this->_hidden_elements[$label]->get_value();          return $this->_hidden_elements[$label]->get_value();
577      }      }
578    
# Line 539  class FormContent { Line 629  class FormContent {
629       * @param string - the form name       * @param string - the form name
630       */       */
631      function set_form_width($width) {      function set_form_width($width) {
632          $this->_form_width = $width;          $this->_width = $width;
633      }      }
634    
635    
636        /**
637         * This method returns the width
638         * of the form errors table.
639         * By default it is supposed to be
640         * the same width as the form itself.
641         *
642         * @return int
643         */
644        function get_form_errors_width() {
645            if ($this->_form_errors_width == null) {
646                return $this->_width;
647            } else {
648                return $this->_form_errors_width;
649            }        
650        }
651    
652        /**
653         * This method allows you to override
654         * the width of the form errors table.
655         * By default it uses the width of the
656         * form as its size.
657         *
658         * @param string - the width
659         */
660        function set_form_errors_width($width) {
661            $this->_form_errors_width = $width;
662        }
663    
664    
665        /**
666         * This allows us to change the form errors
667         * table title
668         *
669         * @param string - the new title
670         */
671        function set_form_errors_title($title) {
672            $this->_form_errors_title = $title;
673        }
674        
675        
676    
677    
678          /**          /**
679           * This function is used to set the           * This function is used to set the
680           * default CSS class used on           * default CSS class used on
# Line 744  class FormContent { Line 876  class FormContent {
876           * @param string - the action           * @param string - the action
877       * @param boolean - disable opon submit?       * @param boolean - disable opon submit?
878           *           *
879           * @return           * @return Atag object
880           */           */
881          function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) {          function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) {
882                  $container = container();                  // Unique button label
   
         $container = new ContainerWidget;  
         // Unique button label  
883          if (!$this->_action_counter) {          if (!$this->_action_counter) {
884              $this->_action_counter = 1;              $this->_action_counter = 1;
885          }          }
886          $blabel = FORM_ACTION.$this->_action_counter;          $blabel = "_form_action".$this->_action_counter;
887          $this->_action_counter++;          $this->_action_counter++;
888    
889          $img = form_image($blabel, $action, $image_name);          $onclick = "document.".$this->_form_name."._form_action.value='".$action."';";
890          //NS 4 hack          $onclick .= "document.".$this->_form_name.".submit();";
891          $img->set_tag_attribute("border", 0 );  
         $img->set_tag_attribute("style", "cursor:hand;");  
         //build the action  
         $onclick = "";  
892          if ($disable_on_submit) {          if ($disable_on_submit) {
893              $onclick .= "this.form.".$blabel.".disabled=true;";              $click = "javascript:if (!window.global_cntr) {window.global_cntr = 1;} else {window.global_cntr++;} ";
894                $click .= " if(window.global_cntr<2) {";
895                $click .= $onclick."}";
896          }          }
897          $onclick .= "this.form.".FORM_ACTION.".value='".$action."';";          
898          $onclick .= "this.form.submit();";          $img = html_img($image_name);
899            $img->set_tag_attribute("border", 0 );
900          $img->set_tag_attribute("onClick", $onclick);          $img->set_tag_attribute("style", "cursor:hand;");
         //IE HACK  
         $container->push($img);  
901    
902          return $container;          $link = html_a("#", $img);
903            $link->set_tag_attribute("onclick", $click);
904            return $link;
905          }          }
906    
907    
# Line 813  class FormContent { Line 941  class FormContent {
941                          return "&nbsp;";                          return "&nbsp;";
942                  }                  }
943          }          }
944        
945        /**
946         * This function is used to set the required field marker
947         *
948         * @param string - the marker
949         */
950         function set_required_marker($marker) {
951             $this->_required_field_marker = $marker;    
952         }
953        
954         /**
955          * This sets the required text
956          *
957          * @param string
958          */
959          function set_required_text($text) {
960              $this->_required_field_text = $text;
961          
962          }
963    
964    
965        /**
966         * This method tests to see if we
967         * have an element named $label,
968         * so we can operate on it.
969         *
970         * @param string - the element's label
971         * @param string - the name of the method that called us
972         * @param boolean - test a hidden element?
973         */
974        function _test_element( $label, $method, $hidden=FALSE ) {
975            if ($hidden) {
976                if (!isset($this->_hidden_elements[$label])) {
977                    trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR);
978                }
979            } else {
980                if (!isset($this->_elements[$label])) {
981                    trigger_error("FormContent::".$method."() - '".$label."' element doesn't exist", E_USER_ERROR);
982                }
983            }        
984        }
985    
986    
987  }  }

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

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