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

Source for file form_field_hid.class.php

Documentation is available at form_field_hid.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id: form_field_hid.class.php 514 2007-04-29 10:55:12Z ogrebg $
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_HID
  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.  * Field that expects valid HID to be provided
  21.  *
  22.  * @package tangra_lib
  23.  * @subpackage form
  24.  */
  25. class Form_Field_HID extends Form_Field_Text {
  26.  
  27.     /**
  28.      * Constructor
  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 100
  33.      * @param string $value Default value.
  34.      */
  35.     function __construct($name$required false$maxlength 100$value NULL{
  36.         parent::__construct($name$required$maxlength$value);
  37.  
  38.         $this->add_potential_error('invalid_hid');
  39.     }
  40.  
  41.     /**
  42.      * Performs basic check for validity
  43.      *
  44.      * @return boolean 
  45.      * @internal
  46.      */
  47.     public function basic_check({
  48.         $has_errors parent::basic_check();
  49.  
  50.         if (!$has_errors{
  51.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  52.                 $max_chars $this->get_maxlength(1;
  53.                 if (!ereg("^[a-z]{1}[a-z0-9_]{0,$max_chars}$"$this->get_html_value())) {
  54.                     $this->set_error('invalid_hid');
  55.                     $has_errors true;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         return $has_errors;
  61.     }
  62. }