Actions

Difference between revisions of "Checkboxes form field type"

From Joomla! Documentation

(Added details via an example.)
m (S:MyLanguage/ missing)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''checkboxes''' form field type provides a set of checkboxes.  
+
<noinclude><languages /></noinclude>
Note: unlike most [[Standard form field types|standard form field types]], such as '''textfield''' or '''checkbox''', this field is not an "out of the box" solution. It will create checkboxes for you, and submit their values in form of an array, but it will not store them in the database.
+
<translate><!--T:1-->
 
+
The '''checkboxes''' form field type provides a set of checkboxes.</translate><br />
Example:
+
<translate><!--T:2-->
 +
Note: unlike most [[S:MyLanguage/Standard form field types|standard form field types]], such as '''textfield''' or '''checkbox''', this field is not an "out of the box" solution. It will create checkboxes for you, and submit their values in form of an array, but it will not store them in the database.</translate>
 +
<translate><!--T:3-->
 +
Example:</translate>
 
<source lang="xml">
 
<source lang="xml">
 
<field name="toppings" type="checkboxes">
 
<field name="toppings" type="checkboxes">
Line 11: Line 14:
 
</field>
 
</field>
 
</source>
 
</source>
The set of checkboxes can be generated in your form with a single statement like this:
+
<translate><!--T:4-->
 +
The set of checkboxes can be generated in your form with a single statement like this:</translate>
 
<source lang="php"><?php echo $this->form->getInput('toppings'); ?></source>
 
<source lang="php"><?php echo $this->form->getInput('toppings'); ?></source>
This will generate the following HTML, which can be styled using CSS:
+
<translate><!--T:5-->
 +
This will generate the following HTML, which can be styled using CSS:</translate>
 
<source lang="html4strict">
 
<source lang="html4strict">
 
<fieldset id="jform_toppings" class="checkboxes">
 
<fieldset id="jform_toppings" class="checkboxes">
Line 28: Line 33:
 
</fieldset>
 
</fieldset>
 
</source>
 
</source>
If the user checks the second and fourth item and submits the form, the Joomla server will provide the following result:
+
<translate><!--T:6-->
 +
If the user checks the second and fourth item and submits the form, the Joomla server will provide the following result:</translate>
 
<source lang="php">
 
<source lang="php">
 
print_r(JRequest::getVar('jform')['toppings']) =>
 
print_r(JRequest::getVar('jform')['toppings']) =>
Line 38: Line 44:
 
)
 
)
 
</source>
 
</source>
 +
 +
<noinclude>
 +
<translate>
 +
<!--T:7-->
 +
[[Category:Standard form field types]]
 +
</translate>
 +
</noinclude>

Latest revision as of 08:12, 14 August 2015

Other languages:
English • ‎français

The checkboxes form field type provides a set of checkboxes.
Note: unlike most standard form field types, such as textfield or checkbox, this field is not an "out of the box" solution. It will create checkboxes for you, and submit their values in form of an array, but it will not store them in the database. Example:

<field name="toppings" type="checkboxes">
    <option value="anch">Anchovies</option>
    <option value="chor">Chorizo</option>
    <option value="on">Onions</option>
    <option value="mush">Mushrooms</option>
</field>

The set of checkboxes can be generated in your form with a single statement like this:

<?php echo $this->form->getInput('toppings'); ?>

This will generate the following HTML, which can be styled using CSS:

<fieldset id="jform_toppings" class="checkboxes">
	<ul>
		<li><input type="checkbox" id="jform_toppings0"
			name="jform[toppings][]" value="anch" /><label for="jform_toppings0">Anchovies</label></li>
		<li><input type="checkbox" id="jform_toppings1"
			name="jform[toppings][]" value="chor" /><label for="jform_toppings1">Chorizo</label></li>
		<li><input type="checkbox" id="jform_toppings2"
			name="jform[toppings][]" value="on" /><label for="jform_toppings2">Onions</label></li>
		<li><input type="checkbox" id="jform_toppings3"
			name="jform[toppings][]" value="mush" /><label for="jform_toppings3">Mushrooms</label></li>
	</ul>
</fieldset>

If the user checks the second and fourth item and submits the form, the Joomla server will provide the following result:

print_r(JRequest::getVar('jform')['toppings']) =>
 
Array
(
    [0] => chor
    [1] => mush
)