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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sat Sep 20 00:18:43 2003 UTC (20 years, 10 months ago) by jonen
Branch: MAIN
Changes since 1.1: +200 -31 lines
+ updated whole phphtmllib to v2.3.0

1 jonen 1.1 <?php
2     /**
3     * This file contains the FormContent class.
4     *
5 jonen 1.2 * $Id: FormContent.inc,v 1.41 2003/07/30 22:23:38 hemna Exp $
6 jonen 1.1 *
7     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
8     * @author Suren Markossian <suren@cbestwhat?>
9     * @package phpHtmlLib
10     * @subpackage FormProcessing
11     *
12     * @copyright LGPL - See LICENCE
13     *
14     */
15    
16     /**
17     * Make sure we include the Processor
18     */
19     require_once($phphtmllib."/form/FormProcessor.inc");
20    
21     /**
22     * This class is used to build and render the form.
23     * It builds a form by creating FormElement objects
24     * which have automatic validation. It leaves the
25     * layout of the form up to the child class. It has
26     * a mechanism in place to automagically show a
27     * confirmation 'page' after the data has been submitted
28     * and validated. It also provides a hook for any
29     * 'back end' validation of data. Finally, it provides
30     * a function for handling the action of the form, which
31     * only gets call after ALL validation has passed.
32     *
33     * Functions:
34     *
35     * form_init_elements() - This function is used to
36     * build the FormElement objects that will be used
37     * by the form. This function is called EVERY time
38     * the FormContent class is instantiated. After you
39     * create the FormElement, you call the
40     * FormContent::add_element() method, to add the
41     * FormElement object to the form. You will then
42     * call the 2 methods FormContent::element_label() and
43     * FormContent::element_form() to get access to the
44     * FormElement's label and form field respectively.
45     *
46     * form_init_data() - This is called only the first time
47     * the form is encountered. It Allows you to populate
48     * the FormElements with data from a DB for example.
49     * You would use FormContent::set_element_value() or
50     * FormContent::set_hidden_element_value() inside here.
51     *
52     * form() - This is the method that gets called to build
53     * the layout for your form. Typically you use a table
54     * and add the label in the first <td> and the form field
55     * itself in the 2nd <td>. So there are 2 methods in
56     * the FormContent object that allow u to get access to
57     * the FormElements label, and form field.
58     * FormContent::element_label() and
59     * FormContent::element_form().
60     *
61     *
62     * form_backend_validation() - This method enables you to
63     * do any "back end" validation of data. Such as, check
64     * for a duplicate in the DB on a create/new form. This
65     * is called after the FormElement's validation methods have
66     * passed.
67     *
68     * form_action() - This method is called after ALL validation
69     * was successfull, including each FormElement object's
70     * validation methods, as well as the FormContent::form_backend_validation()
71     *
72     *
73     *
74     * @package phpHtmlLib
75     * @subpackage FormProcessing
76     */
77     class FormContent {
78    
79     /**
80     * This holds the name of the form
81     * for js that needs it
82     */
83     var $_form_name;
84    
85    
86     /**
87     * This holds the array of
88     * hidden form elements
89     * used in this form
90     */
91     var $_hidden_elements = array();
92    
93     /**
94     * This holds the array of
95     * non-hidden elements
96     */
97     var $_elements = array();
98    
99    
100     /**
101     * This holds the default
102     * css class for form field
103     * label text.
104     *
105     */
106     var $_default_label_css = "formlabel";
107    
108     /**
109     * This is the css class used
110     * for fields that have an error
111     *
112     */
113     var $_error_label_css = "formlabelerror";
114    
115     /**
116     * flag to let the FormProcessor
117     * object know this form has a
118     * confirmation page that is required
119     */
120     var $_has_confirm = FALSE;
121    
122    
123     /**
124     * Holds the width to be used for the
125     * error table
126     * DEFAULT: 95%
127     *
128     */
129     var $_width = "600";
130    
131 jonen 1.2 /**
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 jonen 1.1
146     /**
147     * The message that is set
148     * during the form_action
149     */
150     var $_action_message = "";
151    
152    
153     /**
154     * The action to take opon clicking
155     * the "Cancel" button
156     */
157     var $_cancel_action = NULL;
158    
159    
160     /**
161     * Text to show denoted required
162     * fields for the form.
163     *
164     */
165     var $_required_field_text = " - required field";
166    
167     /**
168     * marker for the required field
169     *
170     */
171     var $_required_field_marker = "*";
172    
173 jonen 1.2 /**
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 jonen 1.1
186    
187     function FormContent($width="100%", $cancel_action=NULL) {
188     $this->set_form_width( $width );
189     $this->set_cancel_action( $cancel_action );
190     }
191    
192     /**
193     * This method is what is called to
194     * build the list of FormElements that
195     * will be used by this form.
196     *
197     */
198     function form_init_elements() {
199     user_error("FormContent::form_init_elements() - Child class must override");
200     }
201    
202    
203     /**
204     * This method is called by the
205     * Form Processor to allow this
206     * class to do any fetching of
207     * data to prepopulate the
208     * form field values.
209     * You typically use this to
210     * read data from a DB.
211     *
212     * This method is only called once
213     * when the form is first hit.
214     *
215     * NOTE: you should build the data
216     * and save it in $this->_init_data
217     */
218     function form_init_data() {
219     $this->_init_data = array();
220     }
221    
222    
223     /**
224     * This method builds the html form.
225     * It is up to the child class to define
226     * the layout of the form and return it
227     * in a phpHtmllib container.
228     *
229     * @return Container
230     */
231     function form() {
232     user_error("FormContent::form() - Child class must override");
233     return NULL;
234     }
235    
236     /**
237 jonen 1.2 * 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 jonen 1.1 * This method allows this class to do any
250     * data munging prior to the form_confirm
251     * method being called @ render time.
252     *
253     * @return TRUE = success
254     * FALSE if u want to trigger an error
255     */
256     function pre_confirm() {
257     return TRUE;
258     }
259    
260    
261    
262     /**
263     * This function is used to show an intermediary
264     * confirmation page. Use this function to
265     * show a confirmation of the data that was
266     * submitted by the user.
267     * This will get called after all of the
268     * form data was successfully validated.
269     * All of the form data will automatically
270     * be created as hidden form fields. All you
271     * have to do is show the data, and a confirm
272     * submit button.
273     *
274 jonen 1.2 * @param string - the title for the table
275     * @param boolean - show the action buttons?
276 jonen 1.1 * @return mixed - either raw html, or some
277 jonen 1.2 * container HTMLTag object.
278 jonen 1.1 */
279 jonen 1.2 function form_confirm( $title = "Form Confirmation", $show_buttons=TRUE ) {
280     $table = new InfoTable($title, $this->_width);
281 jonen 1.1
282     $this->build_confirm_table( $table );
283    
284     //now add the confirmation button
285     $td = new TDtag(array("colspan" => 2,
286     "class" => "contentnovertical",
287     "align" => "center"),
288     $this->add_action("Confirm"));
289    
290     if ($this->_cancel_action) {
291     $td->add(_HTML_SPACE, $this->add_cancel());
292     }
293    
294 jonen 1.2 if ($show_buttons) {
295     $table->add_row( $td );
296     }
297 jonen 1.1
298     return $table;
299     }
300    
301    
302     /**
303     * This method allows the child to ovveride the
304     * default confirm data. By default the form_confirm()
305     * will show ALL FormElements. This is prolly not good
306     * in case of a form where a password exists.
307     *
308     * @param InfoTable object
309     */
310     function build_confirm_table( &$table ) {
311     foreach( $this->_elements as $label => $element) {
312     $c = container(_HTML_SPACE);
313     $c->set_collapse();
314     $value = $element->get_value();
315     if (is_array($value)) {
316     $str = '';
317     foreach($value as $item) {
318     $str .= $element->get_value_text($item).",";
319     }
320     $str = substr($str,0,strlen($str)-1);
321     $c->add( _HTML_SPACE, $str );
322     } else {
323     if (is_a($element, "FEPassword")) {
324     $value = str_repeat('*', strlen($value));
325     $c->add(_HTML_SPACE, $value);
326     } else {
327     $c->add(_HTML_SPACE, $element->get_value_text($value));
328     }
329     }
330     $div = html_div("", $element->get_label() );
331     $div->set_style("white-space:nowrap;");
332     $table->add_row( $div, $c);
333     }
334     }
335    
336     /**
337     * This method is called after the FormElements
338     * have all been validated, and the form_confirm
339     * has been confirmed. It enables the form to
340     * validate any data against a DB or other backend
341     * processing. This will always get called
342     * before the form_action method is called to ensure
343     * that all form data is valid before form_action()
344     * is called.
345     *
346     *
347     * @return boolean TRUE if successfull
348     * FALSE if errors were detected.
349     */
350     function form_backend_validation() {
351     return TRUE;
352     }
353    
354    
355     /**
356     * This method handles the
357     * action (submit button) that
358     * was submitted. This method
359     * only gets called AFTER all
360     * data has been validated.
361     * This includes the backend
362     * validation. If the form
363     * has the confirmation on,
364     * then this method will be
365     * called after the confirmation
366     * has been accepted.
367     *
368     * NOTE : return TRUE if the action
369     * was succesfully handled.
370     * If FALSE is returned, the
371     * form will be displayed again
372     * with the error message.
373     *
374     * @param array - array of errors if any
375     * @return boolean TRUE = success
376     * FALSE = failed.
377     */
378     function form_action() {
379     user_error("FormContent::form_action() - Child class ".
380     "must override");
381     return FALSE;
382     }
383    
384    
385     /**
386     * This method is called when the form_action()
387     * was successfull, and the form wants to render
388     * some kind of message
389     *
390     * @return mixed
391     */
392     function form_success() {
393     return container($this->_action_message, html_br(2));
394     }
395    
396     /**
397     * This function is used to render the error
398     * table for the form. The error data comes
399     * from the FormProcessor or the FormValidation.
400     * NOTE: You can override this method to
401     * show a customized error message(s)
402     *
403     * @return TABLEtag object.
404     */
405     function form_errors() {
406 jonen 1.2 $table = new InfoTable($this->_form_errors_title, $this->get_form_errors_width());
407 jonen 1.1 $errors = FALSE;
408    
409     //walk each visible form element and see if there is an error in it
410     foreach( $this->_elements as $label => $element ) {
411     if ($element->has_error()) {
412 jonen 1.2 $e_errors = $element->get_errors();
413     foreach( $e_errors as $err ) {
414     $span = new SPANtag( array("style" => "padding-right:10px;white-space:nowrap;"),
415     $err['label'] );
416     $table->add_row($span, $err['message']);
417     }
418    
419 jonen 1.1 $errors = TRUE;
420     }
421     }
422     if ($errors) {
423     return $table;
424     } else {
425     return NULL;
426 jonen 1.2 }
427 jonen 1.1 }
428    
429    
430 jonen 1.2 /**
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 jonen 1.1 /*****************************/
452     /* form element methods */
453     /*****************************/
454    
455     /**
456     * This method is used to add a
457     * form element
458     *
459     * @param FormElement object
460     */
461     function add_element( &$element ) {
462 jonen 1.2 $element->set_stripslashes( $this->_stripslashes );
463     //in case the element needs it for js
464     $element->set_form_name( $this->_form_name );
465 jonen 1.1 $this->_elements[$element->get_label_text()] = &$element;
466     }
467    
468     /**
469     * This method is used to add a
470     * hidden form field
471     *
472     * @param FormElement object
473     */
474     function add_hidden_element( $label, $value=NULL ) {
475     $element = new FEHidden( $label, $value );
476 jonen 1.2 $element->set_stripslashes( $this->_stripslashes );
477 jonen 1.1 $this->_hidden_elements[$label] = &$element;
478     }
479    
480     /**
481     * This method returns the label object
482     * for a visible form element.
483     *
484     * @param string - the element's label
485     * @return Object
486     */
487     function element_label($label) {
488 jonen 1.2 $this->_test_element($label, "element_label");
489 jonen 1.1 return $this->_elements[$label]->get_label();
490     }
491    
492     /**
493 jonen 1.2 * 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 jonen 1.1 * This method returns the actual form
506     * object that renders the form field.
507     * Such as an INPUTtag object.
508     *
509     * @param string - the element's label
510     * @return Object
511     */
512     function element_form($label) {
513 jonen 1.2 $this->_test_element($label, "element_form");
514 jonen 1.1 return $this->_elements[$label]->get_element();
515     }
516    
517     /**
518     * This method returns the FormElement
519     * based on the label.
520     *
521     * @param string - the element's label
522     * @return Object
523     */
524     function &get_element($label) {
525 jonen 1.2 $this->_test_element($label, "get_element");
526 jonen 1.1 return $this->_elements[$label];
527     }
528    
529     /**
530     * This method is used to set
531     * the value for a non hidden
532     * element
533     *
534     * @param string - the form label
535     * @param value - the new value
536     */
537     function set_element_value($label, $value) {
538 jonen 1.2 $this->_test_element($label, "set_element_value");
539 jonen 1.1 $this->_elements[$label]->set_value($value);
540     }
541    
542     /**
543     * This method is used to get
544     * the value for a non hidden
545     * element
546     *
547     * @param string - the form label
548     * @return value - the new value
549     */
550     function get_element_value($label) {
551 jonen 1.2 $this->_test_element($label, "get_element_value");
552 jonen 1.1 return $this->_elements[$label]->get_value();
553     }
554    
555     /**
556     * This method is used to set
557     * the value for a hidden element
558     *
559     * @param string - the form label
560     * @param value - the new value
561     */
562     function set_hidden_element_value($label, $value) {
563 jonen 1.2 $this->_test_element($label, "set_hidden_element_value", TRUE);
564 jonen 1.1 $this->_hidden_elements[$label]->set_value( $value );
565     }
566    
567     /**
568     * This method is used to get
569     * the value for a hidden element
570     *
571     * @param string - the form label
572     * @return value - the new value
573     */
574     function get_hidden_element_value($label) {
575 jonen 1.2 $this->_test_element($label, "get_hidden_element_value", TRUE);
576 jonen 1.1 return $this->_hidden_elements[$label]->get_value();
577     }
578    
579    
580     /**
581     * This method is used to create a new error element
582     * during the call to form_action(). This enables us
583     * to do error handling during a transaction into
584     * a DB.
585     *
586     * @param string - the label
587     * @param string - the error message
588     */
589     function add_error( $label, $message ) {
590     if (isset($this->_elements[$label])) {
591     $this->_elements[$label]->set_error_message($message);
592     } else {
593     $this->add_element( new FEError($label, $message) );
594     }
595     }
596    
597    
598     /*****************************/
599     /* Util methods */
600     /*****************************/
601    
602     function set_form_name($name) {
603     $this->_form_name = $name;
604     }
605    
606    
607     /**
608     * Save the action for the form
609     *
610     * @param string - the action from the post.
611     */
612     function set_action($action) {
613     $this->action = $action;
614     }
615    
616     /**
617     * Get the current status of the
618     * action.
619     *
620     * @return string
621     */
622     function get_action() {
623     return $this->action;
624     }
625    
626     /**
627     * this method sets the form name
628     *
629     * @param string - the form name
630     */
631     function set_form_width($width) {
632 jonen 1.2 $this->_width = $width;
633 jonen 1.1 }
634    
635    
636 jonen 1.2 /**
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 jonen 1.1 /**
679     * This function is used to set the
680     * default CSS class used on
681     * form field text when there is no
682     * error on that field
683     *
684     * @param string - the css class to use
685     */
686     function set_default_css( $css ) {
687     $this->_default_label_css = $css;
688     }
689    
690     /**
691     * This function returns the
692     * default css class used for
693     * NON error text.
694     *
695     * @return string - the current default css
696     */
697     function get_default_css() {
698     return $this->_default_label_css;
699     }
700    
701    
702     /**
703     * This function is used to set the
704     * css class that is used on text
705     * when an error on that field is
706     * detected.
707     *
708     * @param string - the css class to use.
709     */
710     function set_error_css( $css ) {
711     $this->_err_label_css = $css;
712     }
713    
714    
715     /**
716     * This sets the $this->_has_confirmation
717     * flag. to let the object know it has
718     * a required confirmation page, which
719     * should get called after the validation
720     * is successfull, and before the action is
721     * handled on the back-end.
722     *
723     * @param boolean - the flag value TRUE/FALSE
724     */
725     function set_confirm( $flag = TRUE ) {
726     $this->_has_confirm = $flag;
727     }
728    
729     /**
730     * This gets the value of the confirmation flag.
731     * which tells the caller that this object
732     * has/doesn't have a required confirmation
733     * page.
734     *
735     * @return boolean
736     */
737     function has_confirm() {
738     return $this->_has_confirm;
739     }
740    
741    
742     /**
743     * This sets the stripslashes flag for
744     * this object.
745     *
746     * @param boolean
747     */
748     function set_stripslashes( $flag = TRUE ) {
749     $this->_stripslashes = $flag;
750     }
751    
752     /**
753     * This sets the action message.
754     * This is called from withint the
755     * form_action() method
756     *
757     * @param string - the action message
758     */
759     function set_action_message($message) {
760     $this->_action_message = $message;
761     }
762    
763    
764     /**
765     * This method sets the javasript action
766     * to be taken when the cancel button
767     * is clicked. Calling this method
768     * w/ a non NULL value automatically enables
769     * the Cancel button.
770     *
771     * @param string - the javascript cancel action
772     */
773     function set_cancel_action($action) {
774     $this->_cancel_action = $action;
775     }
776    
777    
778    
779    
780    
781     /**
782     * This function adds a form submit button
783     * with the appropriate action.
784     *
785     * @param string - the labe/action for the submit
786     * button.
787     * @param bool disable the button
788     * @param string - the onSubmit function (if any)
789     * @param boolean - disable opon submit?
790     * @return INPUTtag object
791     */
792     function add_action( $label, $disabled = false, $submit_function = false,
793     $disable_on_submit = TRUE ) {
794     $style="vertical-align:middle;";
795     // here we mantain a fixed button size if a label length is reasonably small
796     // i.e. OK or Cancel buttons or use padding otherwise
797     if ( strlen($label)<8 ) $style .= "width: 90px;";
798     else $style .= "padding-left: 5px;padding-right:5px;";
799    
800     // Unique button label
801     if (!$this->_action_counter) {
802     $this->_action_counter = 1;
803     }
804     $blabel = FORM_ACTION.$this->_action_counter;
805     $this->_action_counter++;
806    
807     // The onClick is responsible for:
808     // -disabling the action button to discourage stupid users
809     // -setting the action in the _form_action hidden variable
810     // -calling the onSubmit function (if any), since form.submit() will not trigger
811     // the registered onSubmit function
812     // -call the form.submit() function
813    
814     //build the action
815     $onclick = "";
816     if ($disable_on_submit) {
817     $onclick .= "this.form.".$blabel.".disabled=true;";
818     }
819     $onclick .= "this.form.".FORM_ACTION.".value='".$label."';";
820     if ($submit_function) {
821     $onclick .= $submit_function.";";
822     }
823     $onclick .= "this.form.submit();";
824    
825     $attrib = array("style" => $style,
826     "onClick" => $onclick);
827    
828     if ($disabled) $attrib[] = "disabled";
829     return form_submit($blabel, $label, $attrib);
830     }
831    
832    
833     /**
834     * This function adds a submit button that
835     * can have any label. It just makes the
836     * _form_action a hidden field.
837     * NOTE: you can only do this ONCE per form.
838     *
839     * @param string - the label of the button.
840     * @param string - the action value.
841     * @param boolean - disable opon submit?
842     * @return ContainerWidget object
843     */
844     function add_hidden_action( $label, $action, $disable_on_submit=TRUE) {
845     $container = new ContainerWidget;
846     // Unique button label
847     if (!$this->_action_counter) {
848     $this->_action_counter = 1;
849     }
850     $blabel = FORM_ACTION.$this->_action_counter;
851     $this->_action_counter++;
852    
853     //build the action
854     $onclick = "";
855     if ($disable_on_submit) {
856     $onclick .= "this.form.".$blabel.".disabled=true;";
857     }
858     $onclick .= "this.form.".FORM_ACTION.".value='".$action."';";
859     $onclick .= "this.form.submit();";
860    
861     $style = "padding-left: 5px;padding-right:5px;";
862     $attrib = array("style" => $style,
863     "onClick" => $onclick);
864    
865     $container->push(form_submit($blabel, $label,
866     array("style" => $style,
867     "onClick" => $onclick)));
868     return $container;
869     }
870    
871     /**
872     * This function adds an action as an image to
873     * submit the form.
874     *
875     * @param string - the image name path
876     * @param string - the action
877     * @param boolean - disable opon submit?
878     *
879 jonen 1.2 * @return Atag object
880 jonen 1.1 */
881     function add_image_action( $image_name, $action, $disable_on_submit=TRUE ) {
882 jonen 1.2 // Unique button label
883 jonen 1.1 if (!$this->_action_counter) {
884     $this->_action_counter = 1;
885     }
886 jonen 1.2 $blabel = "_form_action".$this->_action_counter;
887 jonen 1.1 $this->_action_counter++;
888    
889 jonen 1.2 $onclick = "document.".$this->_form_name."._form_action.value='".$action."';";
890     $onclick .= "document.".$this->_form_name.".submit();";
891    
892     if ($disable_on_submit) {
893     $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    
898     $img = html_img($image_name);
899 jonen 1.1 $img->set_tag_attribute("border", 0 );
900     $img->set_tag_attribute("style", "cursor:hand;");
901    
902 jonen 1.2 $link = html_a("#", $img);
903     $link->set_tag_attribute("onclick", $click);
904     return $link;
905 jonen 1.1 }
906    
907    
908     /**
909     * build a cancel button with a url
910     * to go to
911     *
912     * @param string - the cancel action
913     * @return form button
914     */
915     function add_cancel() {
916    
917     $cancel_button = form_button("cancel","Cancel",
918     array("type"=>"button",
919     "style"=>"width: 90px;",
920     "onClick"=>
921     "javascript:document.location='".$this->_cancel_action."'"));
922     $cancel_button->set_style("vertical-align:middle");
923     return $cancel_button;
924     }
925    
926    
927     /**
928     * This returns the required field text
929     * if there are any. otherwise it returns NULL
930     *
931     */
932     function get_required_fields_text() {
933     if ( count($this->required_fields) ) {
934    
935     $span = new SPANtag( array( "class" => "formlabel"),
936     $this->_required_field_marker.
937     $this->required_field_text, FALSE );
938    
939     return $span;
940     } else {
941     return "&nbsp;";
942     }
943     }
944 jonen 1.2
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 jonen 1.1
986    
987     }
988     ?>

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