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

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

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

revision 1.1 by jonen, Sat Feb 22 21:07:42 2003 UTC revision 1.2 by jonen, Sat Sep 20 00:18:43 2003 UTC
# Line 58  class FormElement { Line 58  class FormElement {
58      var $_is_required = TRUE;      var $_is_required = TRUE;
59    
60      /**      /**
61         * holds the array of errors
62         * for this element.
63         */
64        var $_errors = array();
65    
66        /**
67       * Holds the error message text       * Holds the error message text
68       * for validation errors, if any       * for validation errors, if any
69       *       *
# Line 98  class FormElement { Line 104  class FormElement {
104       */       */
105      var $_is_disabled = FALSE;      var $_is_disabled = FALSE;
106    
107        /**
108         * automatically strip slashes from
109         * form values?
110         */
111        var $_stripslashes = FALSE;
112    
113    
114        /**
115         * This holds the name of the form
116         * for js that needs it
117         */
118        var $_form_name;
119    
120    
121      /**      /**
122       * The constructor       * The constructor
# Line 145  class FormElement { Line 164  class FormElement {
164       * @return mixed       * @return mixed
165       */       */
166      function get_value() {      function get_value() {
167          return $this->_value;          if ($this->_stripslashes) {
168                return stripslashes($this->_value);
169            } else {
170                return $this->_value;
171            }
172      }      }
173    
174      /**      /**
# Line 159  class FormElement { Line 182  class FormElement {
182      }      }
183    
184      /**      /**
185         * in case anyone in JS land
186         * needs the name of the form that
187         * this element lives in
188         *
189         * @param string - the form name
190         */
191        function set_form_name($name) {
192            $this->_form_name = $name;
193        }
194    
195        /**
196       * This provides a method       * This provides a method
197       * for the FormContent       * for the FormContent
198       * to get access to the       * to get access to the
# Line 204  class FormElement { Line 238  class FormElement {
238       * @return mixed       * @return mixed
239       */       */
240      function get_init_value() {      function get_init_value() {
241          return $_REQUEST[str_replace("[]","",$this->get_element_name())];          return @$_REQUEST[str_replace("[]","",$this->get_element_name())];
242      }      }
243    
244    
# Line 227  class FormElement { Line 261  class FormElement {
261          return $this->_is_disabled;          return $this->_is_disabled;
262      }      }
263    
264            /**
265             * This sets the stripslashes flag for
266             * this object.
267             *
268             * @param boolean
269             */
270            function set_stripslashes( $flag = TRUE ) {
271                    $this->_stripslashes = $flag;
272            }
273    
274    
275      /********* Tag attributes methods *********/      /********* Tag attributes methods *********/
276    
# Line 285  class FormElement { Line 329  class FormElement {
329       * sets the error flag to true       * sets the error flag to true
330       *       *
331       * @param mesage text - error message       * @param mesage text - error message
332       */       * @param label text - a label to provide
333      function set_error_message($message) {       *                     for the error.  This is
334          $this->_error_message = $message;       *                     only needed for a complex
335         *                     element that has multiple
336         *                     'hidden/magic' fields.
337         */
338        function set_error_message($message, $label=NULL) {
339            if ($label == NULL) {
340                $label = $this->get_label_text();
341            }
342            $this->_errors[] = array("label" => $label,
343                                     "message" => $message);
344          $this->_has_error = TRUE;          $this->_has_error = TRUE;
345      }      }
346    
347        /**
348         * This returns the array of errors
349         * for this element
350         *
351         * @param array of errors
352         */
353        function get_errors() {
354            return $this->_errors;
355        }
356    
357    
358      /**      /**
359       * Returns the current error message       * Returns the current error message
# Line 308  class FormElement { Line 371  class FormElement {
371       *       *
372       * @return bool error state       * @return bool error state
373       */       */
374      function has_error() {      function has_error($label=NULL) {
375          return $this->_has_error;          if ($label==NULL) {
376                return $this->_has_error;
377            } else {
378                //xxx( $label );
379                //they are looking for a specific error
380                foreach( $this->_errors as $error) {
381                    
382                    if ($error['label'] == $label) {
383                        xxx( $error['label'] );
384                        return TRUE;
385                    }
386                }
387                return FALSE;
388            }
389            
390      }      }
391    
392    
# Line 357  class FormElement { Line 434  class FormElement {
434       * validation and setting the appropriate error message       * validation and setting the appropriate error message
435       * in case of a failed validation       * in case of a failed validation
436       *       *
437         * @param FormValidation object.
438       */       */
439      function validate() {      function validate(&$_FormValidation) {
440          return TRUE;          return TRUE;
441      }      }
442    
# Line 367  class FormElement { Line 445  class FormElement {
445       * This function checks if the validation       * This function checks if the validation
446       * is nesseccary and calls the validate method       * is nesseccary and calls the validate method
447       *       *
448         * @param FormValidation object.
449       */       */
450      function _do_validation() {      function _do_validation(&$_FormValidation) {
451          if ($this->get_value() != NULL) {          $value = $this->get_value();
452              return $this->validate();          $has_value = FALSE;
453            if (is_array($value)) {
454                foreach($value as $entry) {
455                    if ($entry != NULL) {
456                        $has_value = TRUE;
457                    }
458                }
459            } else {
460                if ($value != NULL) {
461                    $has_value = TRUE;
462                }
463            }
464    
465            if ($has_value && !$this->is_disabled()) {
466                return $this->validate($_FormValidation);
467          } else if ($this->is_required()) {          } else if ($this->is_required()) {
468              $this->set_error_message("This field cannot be empty");              $this->set_error_message("This field cannot be empty");
469              return FALSE;              return FALSE;
# Line 382  class FormElement { Line 475  class FormElement {
475    
476      /********* JavaScript event methods *********/      /********* JavaScript event methods *********/
477    
478    
479        /**
480         * This method is used for adding any javascript
481         * that is used by this element.  This will automatically
482         * get called and added to the page by the FormProcessor
483         *
484         * @return string - raw js
485         */
486        function javascript() {
487            return NULL;
488        }
489    
490      /**      /**
491       * This function return the javaScript code for       * This function return the javaScript code for
492       * an onClick event       * an onClick event
# Line 444  class FormElement { Line 549  class FormElement {
549          $javascript = array();          $javascript = array();
550    
551          if (($js=$this->onClick()) != NULL) {          if (($js=$this->onClick()) != NULL) {
552              $javascript[] = "onClick=\"" . $js . "\"";              $javascript[] = "onclick=\"" . $js . "\"";
553          }          }
554    
555          if (($js=$this->onFocus()) != NULL) {          if (($js=$this->onFocus()) != NULL) {
556              $javascript[] = "onFocus=\"" . $js . "\"";              $javascript[] = "onfocus=\"" . $js . "\"";
557          }          }
558    
559          if (($js=$this->onSubmit()) != NULL) {          if (($js=$this->onSubmit()) != NULL) {
560              $javascript[] = "onSubmit=\"" . $js . "\"";              $javascript[] = "onsubmit=\"" . $js . "\"";
561          }          }
562    
563          if (($js=$this->onBlur()) != NULL) {          if (($js=$this->onBlur()) != NULL) {
564              $javascript[] = "onBlur=\"" . $js . "\"";              $javascript[] = "onblur=\"" . $js . "\"";
565          }          }
566    
567          if (($js=$this->onChange()) != NULL) {          if (($js=$this->onChange()) != NULL) {
568              $javascript[] = "onChange=\"" . $js . "\"";              $javascript[] = "onchange=\"" . $js . "\"";
569          }          }
570    
571          if (count($javascript)>0) {          if (count($javascript)>0) {
# Line 534  class FormElement { Line 639  class FormElement {
639    
640          $span = html_span("formlabel", $label);          $span = html_span("formlabel", $label);
641    
642          if ($this->has_error()) {          if ($this->has_error($label)) {
643              $span->set_tag_attribute("style","color:red;");              $span->set_tag_attribute("style","color:red;");
644          }          }
645    

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