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

Source for file form_field_checkbox.class.php

Documentation is available at form_field_checkbox.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_Checkbox
  8.  *
  9.  * @package  tangra_lib
  10.  * @subpackage  form
  11.  */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once(TANGRA_MAIN_DIR.'form/fields/number/form_field_number.class.php');
  17.  
  18. /**
  19.  * Represents HTML checkbox
  20.  *
  21.  * @package  tangra_lib
  22.  * @subpackage  form
  23.  */
  24. class Form_Field_Checkbox extends Form_Field {
  25.     /**
  26.      * Constructor
  27.      *
  28.      * @param string $name Name of the field
  29.      * @param boolean $required Is field required?
  30.      * @param boolean $value Default value
  31.      */
  32.     function __construct($name$required false$value false{
  33.         parent::__construct($name$value$required);
  34.     }
  35.  
  36.  
  37.     /**
  38.      * Sets fields value
  39.      *
  40.      * @param boolean $value 
  41.      */
  42.     public function set_value($value{
  43.         if ($value{
  44.             parent::set_value(true);
  45.         else {
  46.             parent::set_value(false);
  47.         }
  48.     }
  49.  
  50.  
  51.     /**
  52.      * Captures submit
  53.      *
  54.      * @param form_name $form_name 
  55.      * @param array $submit_array 
  56.      * @internal
  57.      */
  58.     public function capture_submit($form_name&$submit_array{
  59.         if (array_key_exists($form_name.'_'.$this->get_name()$submit_array)) {
  60.             $this->set_html_value($submit_array[$form_name.'_'.$this->get_name()]);
  61.         else {
  62.             $this->set_html_value(NULL);
  63.         }
  64.     }
  65.  
  66.  
  67.     /**
  68.      * Accepts submit
  69.      * @internal
  70.      */
  71.     public function accept_submit({
  72.         $this->translate_value_html2app();
  73.     }
  74.  
  75.  
  76.     /**
  77.      * Returns array with field properties
  78.      *
  79.      * @return array 
  80.      * @internal
  81.      */
  82.     public function get_properties_array({
  83.         $ret parent::get_properties_array();
  84.         $ret['checked'$this->get_value();
  85.         $ret['value'$this->get_name();
  86.         $ret['missing'true;
  87.         return $ret;
  88.     }
  89.  
  90.  
  91.     /**
  92.      * Transfers data from html_value to value
  93.      * @internal
  94.      */
  95.     protected function translate_value_html2app({
  96.         $this->set_value($this->get_html_value(true false);
  97.     }
  98. }