tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file form_field_ereg.class.php

Documentation is available at form_field_ereg.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id: form_field_ereg.class.php 514 2007-04-29 10:55:12Z ogrebg $
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_ereg
  8.  *
  9.  * @package tangra_lib
  10.  * @subpackage form
  11.  */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text.class.php');
  17.  
  18.  
  19. /**
  20.  * Represents text field that is checked for validity against given ereg
  21.  *
  22.  * @package tangra_lib
  23.  * @subpackage form
  24.  */
  25. class Form_Field_Ereg extends Form_Field_Text {
  26.     private $ereg;
  27.  
  28.  
  29.     /**
  30.      * Constructor
  31.      *
  32.      * @param string $name Name of the field
  33.      * @param boolean $required Is field required. Default is false
  34.      * @param integer $maxlength Maximum length of the text. Default is 100
  35.      * @param string $ereg Ereg expression
  36.      * @param string $value Default value.
  37.      */
  38.     function __construct($name$required false$maxlength 100$ereg$value NULL{
  39.         parent::__construct($name$required$maxlength$value);
  40.  
  41.         $this->set_ereg($ereg);
  42.  
  43.         $this->add_potential_error('not_matching_ereg');
  44.     }
  45.  
  46.     /**
  47.      * Performs basic check for validity
  48.      *
  49.      * @return boolean 
  50.      * @internal
  51.      */
  52.     public function basic_check({
  53.         $has_errors parent::basic_check();
  54.  
  55.         if (!$has_errors{
  56.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  57.                 if (!ereg($this->get_ereg()$this->get_html_value())) {
  58.                     $this->set_error('not_matching_ereg');
  59.                     $has_errors true;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         return $has_errors;
  65.     }
  66.  
  67.  
  68.     public function set_ereg($ereg{
  69.         $this->ereg = $ereg;
  70.     }
  71.  
  72.  
  73.     public function get_ereg({
  74.         return $this->ereg;
  75.     }
  76. }