Actions

Difference between revisions of "Checkbox form field type"

From Joomla! Documentation

(Adding a warning about saving unchecked checkboxes. Apparently a lot of component developers come across this as they think joomla handles this. It does not!)
(3 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
* '''name''' (mandatory) is the unique name of the parameter.
 
* '''name''' (mandatory) is the unique name of the parameter.
 
* '''label''' (mandatory) (translatable) is the descriptive title of the field.
 
* '''label''' (mandatory) (translatable) is the descriptive title of the field.
* '''value''' (optional) is the default value of the checkbox. If exist the checkbox will be checked by default.
+
* '''value''' (optional) is the value of the parameter if this checkbox is set (usually 1).
 +
* '''default''' (optional) is the default value (usually 0 or 1).
 
* '''description''' (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the label.
 
* '''description''' (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the label.
 
* '''class''' (optional) is a CSS class name for the HTML form field.  If omitted this will default to 'inputbox'.
 
* '''class''' (optional) is a CSS class name for the HTML form field.  If omitted this will default to 'inputbox'.
 
 
<noinclude>
 
<noinclude>
 +
Example XML field definition:
  
=== Examples XML parameter definition: ===
+
<source lang="xml"><field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" /></source>
 
+
==== Example ====
+
<source lang="xml"><field name="mycheckbox" type="checkbox" label="Show title" description="" value="1" /></source>
+
 
+
==== Example ====
+
<source lang="xml">
+
<field
+
name="kitchen_distribution_option_1"
+
id="kitchen-distribution-option_1"
+
type="checkbox"
+
label="COM_COTIZACION_KITCHEN_DISTRIBUTION_OPTION_1_LABEL"
+
description="COM_COTIZACION_KITCHEN_DISTRIBUTION_OPTION_1_DESC"
+
value="1"
+
/>
+
</source>
+
 
+
  
 +
Example XML field definition (unchecked):
  
 +
<source lang="xml"><field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" default="0" /></source>
  
 +
{{warning|Special care needs to be taken with saving a checkbox from a form!! This is a common mistake. <br>You see, on saving a form with a checkbox that is unchecked, there is no variable for it in the POST information and joomla does not take care of that yet! <br>See Discussion on this page for more.}}
  
 
=== See also ===
 
=== See also ===
 
* [[Standard form field types|List of standard form field types]]
 
* [[Standard form field types|List of standard form field types]]
 
[[Category:Standard form field types]]</noinclude>
 
[[Category:Standard form field types]]</noinclude>

Revision as of 12:37, 29 January 2013

The checkbox form field type provides a single checkbox. If the parameter has a saved value this is selected when the page is first loaded. If not, the default value (if any) is selected.

  • type (mandatory) must be checkbox
  • name (mandatory) is the unique name of the parameter.
  • label (mandatory) (translatable) is the descriptive title of the field.
  • value (optional) is the value of the parameter if this checkbox is set (usually 1).
  • default (optional) is the default value (usually 0 or 1).
  • description (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the label.
  • class (optional) is a CSS class name for the HTML form field. If omitted this will default to 'inputbox'.

Example XML field definition:

<field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" />

Example XML field definition (unchecked):

<field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" default="0" />
Stop hand nuvola.svg.png
Warning!

Special care needs to be taken with saving a checkbox from a form!! This is a common mistake.
You see, on saving a form with a checkbox that is unchecked, there is no variable for it in the POST information and joomla does not take care of that yet!
See Discussion on this page for more.


See also