Source for file jFormsControlCheckbox.class.php

Documentation is available at jFormsControlCheckbox.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  forms
  5. @author      Laurent Jouanneau
  6. @contributor Julien Issler
  7. @copyright   2006-2008 Laurent Jouanneau
  8. @copyright   2008 Julien Issler
  9. @link        http://www.jelix.org
  10. @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  11. */
  12.  
  13. /**
  14.  *
  15.  * @package     jelix
  16.  * @subpackage  forms
  17.  */
  18. class jFormsControlCheckbox extends jFormsControl {
  19.     public $type='checkbox';
  20.     public $defaultValue='0';
  21.     public $valueOnCheck='1';
  22.     public $valueOnUncheck='0';
  23.  
  24.     function __construct($ref){
  25.         $this->ref = $ref;
  26.         $this->datatype = new jDatatypeBoolean();
  27.     }
  28.  
  29.     function check(){
  30.         $value $this->container->data[$this->ref];
  31.         if($this->required && $value == $this->valueOnUncheck)
  32.             return $this->container->errors[$this->refjForms::ERRDATA_REQUIRED;
  33.         if($value != $this->valueOnCheck && $value != $this->valueOnUncheck)
  34.             return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  35.         return null;
  36.     }
  37.  
  38.     function setValueFromRequest($request{
  39.         $value $request->getParam($this->ref);
  40.         if($value){
  41.             $this->setData($this->valueOnCheck);
  42.         }else{
  43.             $this->setData($this->valueOnUncheck);
  44.         }
  45.     }
  46.  
  47.     function setData($value{
  48.         $value = (string) $value;
  49.         if($value != $this->valueOnCheck){
  50.             if($value =='on')
  51.                 $value $this->valueOnCheck;
  52.             else
  53.                 $value $this->valueOnUncheck;
  54.         }
  55.         parent::setData($value);
  56.     }
  57.  
  58.     function setDataFromDao($value$daoDatatype{
  59.         if$daoDatatype == 'boolean'{
  60.             if(strtolower($value== 'true' ||  $value === 't'|| intval($value== || $value === 'on' || $value === true){
  61.                 $value $this->valueOnCheck;
  62.             }else {
  63.                 $value $this->valueOnUncheck;
  64.             }
  65.         }
  66.         $this->setData($value);
  67.     }
  68.  
  69. }

Documentation generated on Thu, 19 Sep 2013 00:05:02 +0200 by phpDocumentor 1.4.3