Source for file checkbox.php

Documentation is available at checkbox.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Form Field class for the Joomla Platform.
  14.  * Single check box field.
  15.  * This is a boolean field with null for false and the specified option for true
  16.  *
  17.  * @package     Joomla.Platform
  18.  * @subpackage  Form
  19.  * @link        http://www.w3.org/TR/html-markup/input.checkbox.html#input.checkbox
  20.  * @see         JFormFieldCheckboxes
  21.  * @since       11.1
  22.  */
  23. {
  24.     /**
  25.      * The form field type.
  26.      *
  27.      * @var    string 
  28.      * @since  11.1
  29.      */
  30.     protected $type = 'Checkbox';
  31.  
  32.     /**
  33.      * The checked state of checkbox field.
  34.      *
  35.      * @var    boolean 
  36.      * @since  3.2
  37.      */
  38.     protected $checked = false;
  39.  
  40.     /**
  41.      * Method to get certain otherwise inaccessible properties from the form field object.
  42.      *
  43.      * @param   string  $name  The property name for which to the the value.
  44.      *
  45.      * @return  mixed  The property value or null.
  46.      *
  47.      * @since   3.2
  48.      */
  49.     public function __get($name)
  50.     {
  51.         switch ($name)
  52.         {
  53.             case 'checked':
  54.                 return $this->$name;
  55.         }
  56.  
  57.         return parent::__get($name);
  58.     }
  59.  
  60.     /**
  61.      * Method to set certain otherwise inaccessible properties of the form field object.
  62.      *
  63.      * @param   string  $name   The property name for which to the the value.
  64.      * @param   mixed   $value  The value of the property.
  65.      *
  66.      * @return  void 
  67.      *
  68.      * @since   3.2
  69.      */
  70.     public function __set($name$value)
  71.     {
  72.         switch ($name)
  73.         {
  74.             case 'checked':
  75.                 $value = (string) $value;
  76.                 $this->$name ($value == 'true' || $value == $name || $value == '1');
  77.                 break;
  78.  
  79.             default:
  80.                 parent::__set($name$value);
  81.         }
  82.     }
  83.  
  84.     /**
  85.      * Method to attach a JForm object to the field.
  86.      *
  87.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  88.      * @param   mixed             $value    The form field value to validate.
  89.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  90.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  91.      *                                       full field name would end up being "bar[foo]".
  92.      *
  93.      * @return  boolean  True on success.
  94.      *
  95.      * @see     JFormField::setup()
  96.      * @since   3.2
  97.      */
  98.     public function setup(SimpleXMLElement $element$value$group null)
  99.     {
  100.         $return parent::setup($element$value$group);
  101.  
  102.         if ($return)
  103.         {
  104.             $checked = (string) $this->element['checked'];
  105.             $this->checked = ($checked == 'true' || $checked == 'checked' || $checked == '1');
  106.  
  107.             empty($this->value|| $this->checked ? null $this->checked = true;
  108.         }
  109.  
  110.         return $return;
  111.     }
  112.  
  113.     /**
  114.      * Method to get the field input markup.
  115.      * The checked element sets the field to selected.
  116.      *
  117.      * @return  string  The field input markup.
  118.      *
  119.      * @since   11.1
  120.      */
  121.     protected function getInput()
  122.     {
  123.         // Initialize some field attributes.
  124.         $class     !empty($this->class' class="' $this->class . '"' '';
  125.         $disabled  $this->disabled ? ' disabled' '';
  126.         $value     !empty($this->default$this->default : '1';
  127.         $required  $this->required ? ' required aria-required="true"' '';
  128.         $autofocus $this->autofocus ? ' autofocus' '';
  129.         $checked   $this->checked || !empty($this->value' checked' '';
  130.  
  131.         // Initialize JavaScript field attributes.
  132.         $onclick  !empty($this->onclick' onclick="' $this->onclick . '"' '';
  133.         $onchange !empty($this->onchange' onchange="' $this->onchange . '"' '';
  134.  
  135.         // Including fallback code for HTML5 non supported browsers.
  136.         JHtml::_('jquery.framework');
  137.         JHtml::_('script''system/html5fallback.js'falsetrue);
  138.  
  139.         return '<input type="checkbox" name="' $this->name . '" id="' $this->id . '" value="'
  140.             . htmlspecialchars($valueENT_COMPAT'UTF-8''"' $class $checked $disabled $onclick $onchange
  141.             . $required $autofocus ' />';
  142.     }
  143. }

Documentation generated on Tue, 19 Nov 2013 14:55:40 +0100 by phpDocumentor 1.4.3