Difference between revisions of "Checkbox form field type"
From Joomla! Documentation
m (There is no drop-down box screen element) |
ADaneInSpain (talk | contribs) (Removed references to "default" as it is not relevant on a checkbox and added the attribute "checked" which was missing) |
||
(11 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
− | 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. | + | <noinclude><languages /></noinclude> |
+ | <translate><!--T:1--> | ||
+ | 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.</translate> | ||
− | * '''type''' (mandatory) must be checkbox | + | <translate><!--T:2--> |
+ | * '''type''' (mandatory) must be checkbox</translate> | ||
* '''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. | + | <translate><!--T:3--> |
− | * '''value''' (optional) is the | + | * '''label''' (mandatory) (translatable) is the descriptive title of the field.</translate> |
− | * '''description''' (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the label. | + | <translate><!--T:4--> |
− | * '''class''' (optional) is a CSS class name for the HTML form field. If omitted this will default to 'inputbox'. | + | * '''value''' (optional) is the value of the parameter if this checkbox is set (usually 1).</translate> |
+ | <translate><!--T:5--> | ||
+ | * '''checked''' (optional) should be set to 1 to check the checkbox by default or 0 not to.</translate> | ||
+ | <translate><!--T:6--> | ||
+ | * '''description''' (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the label.</translate> | ||
+ | <translate><!--T:7--> | ||
+ | * '''class''' (optional) is a CSS class name for the HTML form field. If omitted this will default to 'inputbox'.</translate> | ||
+ | |||
+ | <translate><!--T:8--> | ||
+ | Example XML field definition:</translate> | ||
+ | <source lang="xml"><field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" /></source> | ||
+ | |||
+ | <translate><!--T:9--> | ||
+ | Example XML field definition (checked):</translate> | ||
+ | |||
+ | <source lang="xml"><field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" checked="1" /></source> | ||
+ | |||
+ | |||
+ | {{warning|<translate><!--T:10--> | ||
+ | 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 [[Talk:Checkbox form field type|this page]] for more.</translate>}} | ||
+ | <translate>=== See also === <!--T:11--></translate> | ||
+ | <translate><!--T:12--> | ||
+ | * [[S:MyLanguage/Standard form field types|List of standard form field types]]</translate> | ||
− | |||
− | |||
<noinclude> | <noinclude> | ||
− | + | <translate> | |
− | + | <!--T:13--> | |
− | [[Category:Standard form field types]]</noinclude> | + | [[Category:Standard form field types]] |
+ | </translate> | ||
+ | </noinclude> |
Latest revision as of 08:05, 11 October 2018
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).
- checked (optional) should be set to 1 to check the checkbox by default or 0 not to.
- 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 (checked):
<field name="show_title" type="checkbox" label="Show title" description="Show the title of the item" value="1" checked="1" />
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.