checkbox() public method

### Options: - value - the value of the checkbox - checked - boolean indicate that this checkbox is checked. - hiddenField - boolean to indicate if you want the results of checkbox() to include a hidden input with a value of ''. - disabled - create a disabled input. - default - Set the default value for the checkbox. This allows you to start checkboxes as checked, without having to check the POST data. A matching POST data value, will overwrite the default value.
public checkbox ( string $fieldName, array $options = [] ) : string | array
$fieldName string Name of a field, like this "modelname.fieldname"
$options array Array of HTML attributes.
return string | array An HTML text input element.
Beispiel #1
0
 /**
  * Creates a checkbox input element
  * @param string $fieldName Field name, should be "Modelname.fieldname"
  * @param array $options HTML attributes and options
  * @return string
  */
 public function checkbox($fieldName, array $options = [])
 {
     if (!isset($options['hiddenField']) || !empty($options['hiddenField'])) {
         $options['hiddenField'] = true;
     }
     return parent::checkbox($fieldName, $options);
 }
Beispiel #2
0
 /**
  * Create and render ace checkbox.
  *
  * @param string $fieldName
  * @param array $options
  * @return array|string
  */
 public function checkbox($fieldName, array $options = [])
 {
     $viewForm = $this->_View->Form;
     $options = $this->addClass($options, 'ace');
     if (is_object($viewForm->_context)) {
         if (!is_null($viewForm->_context->val($fieldName))) {
             $options['val'] = $viewForm->_context->val($fieldName);
         }
         if (!in_array($fieldName, $viewForm->fields)) {
             $this->_View->Form->fields[] = $fieldName;
         }
     }
     return parent::checkbox($fieldName, $options);
 }