My component needs to save mulitple options, and I can't seem to get my head wrapped around how to do it. Referring to Checkboxes form field type, I'm not sure how Joomla is expecting to save the options that the user has selected.
Update: To be clear, i'm referring to the plural checkboxes
field type, not checkbox
.
Here's the XML that I'm using:
<field name="content_subrating"
label="Content Subrating"
type="checkboxes"
>
<option value="D">Suggestive Dialog</option>
<option value="L">Course Language</option>
<option value="S">Sexual Content</option>
<option value="V">Violence</option>
</field>
Resulting HTML
<fieldset class="checkboxes" id="jform_content_subrating">
<ul>
<li>
<input type="checkbox" checked="" value="D" name="jform[content_subrating][]" id="jform_content_subrating0">
<label for="jform_content_subrating0" aria-invalid="false">Suggestive Dialog</label>
</li>
<li>
<input type="checkbox" value="L" name="jform[content_subrating][]" id="jform_content_subrating1">
<label for="jform_content_subrating1">Course Language</label>
</li>
<li>
<input type="checkbox" value="S" name="jform[content_subrating][]" id="jform_content_subrating2">
<label for="jform_content_subrating2">Sexual Content</label>
</li>
<li>
<input type="checkbox" value="V" name="jform[content_subrating][]" id="jform_content_subrating3">
<label for="jform_content_subrating3">Violence</label>
</li>
</ul>
</fieldset>
And the resulting input:
JRequest::getVar('jform')['content_subrating']) =>
Array
(
[0] => L
[1] => V
)
In my perfect world, it would concatenate all the value and store them in one column, but I don't expect that's what Joomla would do by default. If not, then how would one specify which values go to where such that Joomla can later understand how to retrieve the values. I'm sure I'm missing something obvious, but I'm stuck.
Can someone explain how Joomla deals with this, or give me a core example that does?
Conclusion: It seems that this field type is merely a short hand method of easily creating multiple checkboxes, all of which have the inherent problem of submitting nothing if unchecked. Because they're submitted as an array, it seems handy enough as long as you're merely processing based on the values being submitted, but seems like a lot of unnecessary work if you ever need to retrieve them. (Just my opinion, I could be wrong)
Further Realization (at the very top of the documentation!):
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.