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

Source for file form_field_number_fixed.class.php

Documentation is available at form_field_number_fixed.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_Date
  8.  *
  9.  * @package tangra_lib
  10.  * @subpackage form
  11.  */
  12.  
  13.  
  14. /**
  15.  *
  16.  */
  17. require_once(TANGRA_MAIN_DIR.'form/fields/number/form_field_number.class.php');
  18.  
  19.  
  20.  
  21. /**
  22.  * Represents text field that accepts number with fixed number of digits
  23.  *
  24.  * @package tangra_lib
  25.  * @subpackage form
  26.  */
  27.     /**
  28.      * Enter description here...
  29.      *
  30.      * @param string $name Name of the field
  31.      * @param boolean $required Is field required. Default is false
  32.      * @param integer $maxlength Maximum length of the text. Default is 10
  33.      * @param string $value Default value.
  34.      */
  35.     function __construct($name$required false$maxlength 10$value NULL{
  36.         parent::__construct($name$required$maxlength$value);
  37.  
  38.         $this->add_potential_error('invalid_numeric_fixed');
  39.     }
  40.  
  41.  
  42.     /**
  43.      * Performs basic check for validity
  44.      *
  45.      * @return boolean 
  46.      * @internal
  47.      */
  48.     public function basic_check({
  49.         $has_errors parent::basic_check();
  50.  
  51.         if (!$has_errors{
  52.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  53.                 if (!ereg('^[0-9]{1,'.$this->get_maxlength().'}$'trim($this->get_html_value()))) {
  54.                     $this->set_error('not_an_integer');
  55.                     $has_errors true;
  56.                 else {
  57.                     if (strlen($this->get_html_value()) <> $this->get_maxlength()) {
  58.                         $this->set_error('invalid_numeric_fixed');
  59.                         $has_errors true;
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.  
  65.         return $has_errors;
  66.     }
  67. }