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

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

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

revision 1.1 by jonen, Sat Feb 22 21:07:48 2003 UTC revision 1.4 by jonen, Thu Aug 11 14:09:59 2005 UTC
# Line 5  Line 5 
5   *   *
6   * $Id$   * $Id$
7   *   *
8   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
9   * @author Suren Markosyan <suren@bcsweb.com>   * @author Suren Markosyan <suren@bcsweb.com>
10   * @package phpHtmlLib   * @package phpHtmlLib
11   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 19  Line 19 
19   * text input field. It has no validation method.   * text input field. It has no validation method.
20   *   *
21   *   *
22   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
23   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
24   * @package phpHtmlLib   * @package phpHtmlLib
25   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 36  class FEText extends FormElement { Line 36  class FEText extends FormElement {
36       * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)       * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
37       * @param int required - maximum number of chars allowed to type in       * @param int required - maximum number of chars allowed to type in
38       */       */
39      function FEText($label, $required = TRUE, $width = NULL, $maxlength = NULL) {      function FEText($label, $required = FALSE, $width = NULL, $maxlength = NULL) {
40          $this->FormElement($label, $required);          $this->FormElement($label, $required);
41    
42          if ($width != NULL) {          if ($width != NULL) {
# Line 65  class FEText extends FormElement { Line 65  class FEText extends FormElement {
65          if (($value = $this->get_value()) != NULL)          if (($value = $this->get_value()) != NULL)
66              $attributes["value"] = $value;              $attributes["value"] = $value;
67    
68          $tag = new INPUTtag($attributes);          return new INPUTtag($attributes);
           
   
         return $tag;  
69      }      }
70  }  }
71    
# Line 77  class FEText extends FormElement { Line 74  class FEText extends FormElement {
74   * text input field, and validates against the   * text input field, and validates against the
75   * is_name() method.   * is_name() method.
76   *   *
77   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
78   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
79   * @package phpHtmlLib   * @package phpHtmlLib
80   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 91  class FEName extends FEText { Line 88  class FEName extends FEText {
88       * for this Form Element.       * for this Form Element.
89       *       *
90       * It validates as is_name().       * It validates as is_name().
91         * @param FormValidation object.
92       */       */
93      function validate() {      function validate(&$_FormValidation) {
94          $v = new FormValidation;          if (!$_FormValidation->is_name($this->get_value())) {
95          if (!$v->is_name($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
96              return FALSE;              return FALSE;
97          }          }
98          return TRUE;          return TRUE;
# Line 108  class FEName extends FEText { Line 105  class FEName extends FEText {
105   * It validatest he data as is_email()   * It validatest he data as is_email()
106   *   *
107   *   *
108   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
109   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
110   * @package phpHtmlLib   * @package phpHtmlLib
111   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 116  class FEName extends FEText { Line 113  class FEName extends FEText {
113   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
114   */   */
115  class FEEmail extends FEText {  class FEEmail extends FEText {
116        
117        /** Holds the flag to indicate
118          * whether we allow email in
119          * the long name format like
120          * Foo Bar <email@email.com>
121          */
122        var $_allow_name = true;    
123    
124      /**      /**
125       * This method validates the data       * This method validates the data
126       * for this Form Element.       * for this Form Element.
127       *       *
128       * It validates as is_email().       * It validates as is_email().
129         * @param FormValidation object.
130       */       */
131      function validate() {      function validate($_FormValidation) {
132          $v = new FormValidation;          if (!$_FormValidation->is_email($this->get_value(), $this->_allow_name)) {
133          if (!$v->is_email($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
134              return FALSE;              return FALSE;
135          }          }
136          return TRUE;          return TRUE;
137      }      }
138    
139        /**
140         * Sets the flag to indicate
141         * whether we allow email in
142         * the long name format like
143         * Foo Bar <email@email.com>
144         *
145         * @param bool
146         */
147        function set_allow_name($flag) {
148            $this->_allow_name = $flag;
149        }    
150  }  }
151    
152  /**  /**
# Line 141  class FEEmail extends FEText { Line 157  class FEEmail extends FEText {
157   * It validatest he data as is_manyemails()   * It validatest he data as is_manyemails()
158   *   *
159   *   *
160   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
161   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
162   * @package phpHtmlLib   * @package phpHtmlLib
163   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 155  class FEEmailMany extends FEText { Line 171  class FEEmailMany extends FEText {
171       * for this Form Element.       * for this Form Element.
172       *       *
173       * It validates as is_manyemails().       * It validates as is_manyemails().
174         * @param FormValidation object.
175       */       */
176      function validate() {      function validate(&$_FormValidation) {
177          $v = new FormValidation;          if (!$_FormValidation->is_manyemails($this->get_value())) {
178          if (!$v->is_manyemails($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
179              return FALSE;              return FALSE;
180          }          }
181          return TRUE;          return TRUE;
# Line 172  class FEEmailMany extends FEText { Line 188  class FEEmailMany extends FEText {
188   * It validates as is_domainname().   * It validates as is_domainname().
189   *   *
190   *   *
191   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
192   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
193   * @package phpHtmlLib   * @package phpHtmlLib
194   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 186  class FEDomainName extends FEText { Line 202  class FEDomainName extends FEText {
202       * for this Form Element.       * for this Form Element.
203       *       *
204       * It validates as is_domainname().       * It validates as is_domainname().
205         * @param FormValidation object.
206       */       */
207      function validate() {      function validate(&$_FormValidation) {
208          $v = new FormValidation;          if (!$_FormValidation->is_domainname($this->get_value())) {
209          if (!$v->is_domainname($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
210              return FALSE;              return FALSE;
211          }          }
212          return TRUE;          return TRUE;
# Line 198  class FEDomainName extends FEText { Line 214  class FEDomainName extends FEText {
214  }  }
215    
216  /**  /**
217   * This is the Ip Address FormElement which builds a   * This is the DomainName FormElement which builds a
218   * text input field.   * text input field. It also includes a port #
219   * It validates as is_ip().   * It validates as is_domainname().
220   *   *
221   *   *
222   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
223   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
224   * @package phpHtmlLib   * @package phpHtmlLib
225   * @subpackage FormProcessing   * @subpackage FormProcessing
226   *   *
227   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
228   */   */
229  class FEIPAddress extends FEText {  class FEHostNameWithPort extends FEText {
230    
231        /**
232         * flag to tell us to seperate the port
233         * value into it's own field
234         */
235        var $_seperate_port_flag = FALSE;
236    
237        /**
238         * The constructor
239         *
240         * @param label string - text label for the element
241         * @param bool required - is this a required element
242         * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
243         * @param int required - maximum number of chars allowed to type in
244         * @param bool optional - seperate the port value into it's own textarea field
245         */
246        function FEHostNameWithPort($label, $required = TRUE, $width = NULL, $maxlength = NULL,
247                                      $seperate_port=FALSE) {
248            $this->FEText($label, $required, $width, $maxlength);
249            $this->_seperate_port_flag = $seperate_port;
250        }
251    
252        /**
253         * This function builds and returns the
254         * form element object
255         *
256         * @return object
257         */
258        function get_element() {
259            $host_attributes = $this->_build_element_attributes();
260            $host_attributes["type"] = "text";
261    
262            $element_name = $this->get_element_name();                
263            $host_value = $this->get_value();
264    
265            if ($this->_seperate_port_flag) {
266                $host_attributes["name"] = $element_name."[0]";
267                if ($host_value != NULL && !is_array($host_value)) {
268                    $host_value = explode(":", $host_value );
269                    $host_attributes["value"] = $host_value[0];
270                } else if (is_array($host_value)) {
271                    $host_attributes["value"] = $host_value[0];
272                }
273    
274                $port_attributes = $host_attributes;
275                $port_attributes["name"] = $element_name."[1]";
276                $port_attributes["size"] = 10;
277                $port_attributes["maxlenght"] = 5;
278                if (@array_key_exists("0", $host_value)) {
279                    $port_attributes["value"] = $host_value[1];
280                }
281    
282                $port_label = html_span("formlabel", "Port");
283                if ($this->has_error("Port")) {
284                    $port_label->set_tag_attribute("style","color:red;");
285                }            
286    
287                return container( new INPUTtag($host_attributes),
288                                  $port_label,
289                                  new INPUTtag($port_attributes));
290            } else {
291                if ($host_value != NULL) {
292                    $host_attributes["value"] = $host_value;
293                }
294                return new INPUTtag($host_attributes);
295            }
296        }
297    
298      /**      /**
299       * This method validates the data       * This method validates the data
300       * for this Form Element.       * for this Form Element.
301       *       *
302       * It validates as is_ip().       * It validates as is_domainname().
303         * @param FormValidation object.
304       */       */
305      function validate() {      function validate(&$_FormValidation) {
306          $v = new FormValidation;          $value = $this->get_value();
307          if (!$v->is_ip($this->get_value())) {          if (!is_array($value)) {
308              $this->set_error_message( $v->get_error_message() );              $value = explode(":", $value);
             return FALSE;  
309          }          }
310          return TRUE;          
311            $valid = $this->_validate_hostname($_FormValidation, $value[0]);
312    
313            //now validate the port
314            if ($value[1] != NULL) {
315                if (!$_FormValidation->is_number($value[1])) {
316                    if ($this->_seperate_port_flag) {
317                        $this->set_error_message($_FormValidation->get_error_message(), "Port");
318                    } else {
319                        $this->set_error_message( $_FormValidation->get_error_message() );
320                    }
321                    $value = FALSE;
322                }
323    
324                //make sure the hostname isn't null
325                if ($value[0] == NULL) {
326                    //we have an error here because
327                    //they entered a port w/o a hostname
328                    $_FormValidation->_error("", "This field cannot be empty, if the Port is filled out");
329                    $this->set_error_message($_FormValidation->get_error_message());
330                }
331            }
332            return $valid;
333        }
334    
335    
336        /**
337         * this validates the hostname field only
338         *
339         * @return bool TRUE = valid
340         */
341        function _validate_hostname(&$_FormValidation, $value) {
342            $valid = TRUE;
343            //validate the hostname        
344            if ($value != NULL && !$_FormValidation->is_hostname($value)) {
345                $this->set_error_message( $_FormValidation->get_error_message() );
346                $valid = FALSE;
347            }
348    
349            return $valid;
350      }      }
351  }  }
352    
353  /**  /**
354   * This is the float FormElement which builds a   * This is the Ip Address FormElement which builds a
355   * text input field.   * text input field.
356   * It validates as is_float().   * It validates as is_ip().
357   *   *
358   *   *
359   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
360   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
361   * @package phpHtmlLib   * @package phpHtmlLib
362   * @subpackage FormProcessing   * @subpackage FormProcessing
363   *   *
364   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
365   */   */
366  class FENumberFloat extends FEText {  class FEIPAddress extends FEText {
367    
368      /**      /**
369       * This method validates the data       * This method validates the data
370       * for this Form Element.       * for this Form Element.
371       *       *
372       * It validates as is_float().       * It validates as is_ip().
373         * @param FormValidation object.
374       */       */
375      function validate() {      function validate(&$_FormValidation) {
376          $v = new FormValidation;          if (!$_FormValidation->is_ip($this->get_value())) {
377          if (!$v->is_float($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
378              return FALSE;              return FALSE;
379          }          }
380          return TRUE;          return TRUE;
# Line 260  class FENumberFloat extends FEText { Line 382  class FENumberFloat extends FEText {
382  }  }
383    
384  /**  /**
385   * This is the Price FormElement which builds a   * This is the Ip Address FormElement which builds a
386   * text input field.   * text input field.
387   * It validates as is_price().   * It validates as is_ip().
388   *   *
389   *   *
390   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
391   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
392   * @package phpHtmlLib   * @package phpHtmlLib
393   * @subpackage FormProcessing   * @subpackage FormProcessing
394   *   *
395   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
396   */   */
397  class FENumberPrice extends FEText {  class FEIPAddressWithPort extends FEHostNameWithPort {
398    
399      /**      /**
400       * This method validates the data       * this validates the hostname field only
401       * for this Form Element.       *
402       *       * @return bool TRUE = valid
403       * It validates as is_price().       */
404       */      function _validate_hostname(&$_FormValidation, $value) {
405      function validate() {          $valid = TRUE;
406          $v = new FormValidation;          //validate the hostname        
407          if (!$v->is_price($this->get_value())) {          if ($value != NULL && !$_FormValidation->is_ip($value)) {
408              $this->set_error_message( $v->get_error_message() );              $this->set_error_message( $_FormValidation->get_error_message() );
409              return FALSE;              $valid = FALSE;
410          }          }
411          return TRUE;          return $valid;
412      }      }
413  }  }
414    
415    
416    
417  /**  /**
418   * This is the URL FormElement which builds a   * This is the URL FormElement which builds a
419   * text input field.   * text input field.
420   * It validates as is_url().   * It validates as is_url().
421   *   *
422   *   *
423   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
424   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
425   * @package phpHtmlLib   * @package phpHtmlLib
426   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 310  class FEUrl extends FEText { Line 434  class FEUrl extends FEText {
434       * for this Form Element.       * for this Form Element.
435       *       *
436       * It validates as is_url().       * It validates as is_url().
437         * @param FormValidation object.
438       */       */
439      function validate() {      function validate(&$_FormValidation) {
440          $v = new FormValidation;          if (!$_FormValidation->is_url($this->get_value())) {
441          if (!$v->is_url($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
             $this->set_error_message( $v->get_error_message() );  
442              return FALSE;              return FALSE;
443          }          }
444          return TRUE;          return TRUE;
# Line 328  class FEUrl extends FEText { Line 452  class FEUrl extends FEText {
452   * It validates as is_strict_url().   * It validates as is_strict_url().
453   *   *
454   *   *
455   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
456   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
457   * @package phpHtmlLib   * @package phpHtmlLib
458   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 342  class FEUrlStrict extends FEText { Line 466  class FEUrlStrict extends FEText {
466       * for this Form Element.       * for this Form Element.
467       *       *
468       * It validates as is_strict_url().       * It validates as is_strict_url().
469         * @param FormValidation object.
470         */
471        function validate(&$_FormValidation) {
472            if (!$_FormValidation->is_strict_url($this->get_value())) {
473                $this->set_error_message( $_FormValidation->get_error_message() );
474                return FALSE;
475            }
476            return TRUE;
477        }
478    }
479    
480    /**
481     * This is the FEZipcode class.
482     *
483     * @author Walter A. Boring IV <waboring@newsblob.com>
484     */
485    class FEZipcode extends FEText {
486        /**
487         * The constructor
488         *
489         * @param label string - text label for the element
490         * @param bool required - is this a required element
491         * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
492         * @param int required - maximum number of chars allowed to type in
493         */
494        function FEZipcode($label, $required=false, $width = NULL, $maxlength = 5) {
495            $this->FEText($label, $required, $width, $maxlength);
496        }
497    
498    
499        /**
500         * This method validates the data
501         * for this Form Element.
502         *
503         * It validates as is_name().
504         * @param FormValidation object.
505       */       */
506      function validate() {      function validate(&$_FormValidation) {
507          $v = new FormValidation;          if (!$_FormValidation->is_zip($this->get_value())) {
508          if (!$v->is_strict_url($this->get_value())) {              $this->set_error_message( $_FormValidation->get_error_message() );
509              $this->set_error_message( $v->get_error_message() );              return FALSE;
510            }
511            return TRUE;
512        }
513    }
514    
515    /**
516     * This is the RegEx FormElement which builds a text input field, and validates
517     * against the is_regex() method.
518     *
519     * Example as it would appear in FormContent::form_init_elements():
520     * <code>
521     *      $this->add_element( new FERegEx("FERegEx label", false, '200px', 3, '/^pattern to match$/', 'error message when pattern does not match') );
522     * </code>
523     *
524     * @author Culley Harrelson <culley@fastmail.fm>
525     * @package phpHtmlLib
526     * @subpackage FormProcessing
527     *
528     * @copyright LGPL - See LICENCE
529     */
530    class FERegEx extends FEText {
531    
532        var $_regex;
533        var $_error_message;
534    
535        /**
536         * The constructor
537         *
538         * @param label string - text label for the element
539         * @param required bool- is this a required element
540         * @param width int - element width in characters, pixels (px), percentage (%) or elements (em)
541         * @param maxlength int- maximum number of chars allowed to type in
542         * @param regex string - a valid regular expression i.e. '/[a-z]+$/i'
543         * @param error_message string - error message for failure to match the regex
544         */
545        function FERegEx($label, $required=false, $width = NULL, $maxlength = NULL, $regex, $error_message) {
546            $this->FEText($label, $required, $width, $maxlength);
547            $this->_regex = $regex;
548            $this->_error_message = $error_message;
549        }
550    
551        /**
552         * This method validates the data
553         * for this Form Element.
554         *
555         * It validates as is_regex().
556         * @param FormValidation object.
557         * @return boolean
558         */
559        function validate(&$_FormValidation) {
560            if (!$_FormValidation->is_regex($this->_regex, $this->get_value())) {
561                $this->set_error_message( $this->_error_message );
562              return FALSE;              return FALSE;
563          }          }
564          return TRUE;          return TRUE;

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