Joomla Custom Form Field that turns SQL into checkboxes
We love Joomla! We said it before and we'll say it again. It has given us soo much so it's once again time to return something to the community. Something that we noted was missing is a SQL Form Field that doesnt drop us a select box but gives our users multiple checkboxes. The SQL Form Field has a "multiple" attribute that gives a multiple option select box, but well: It's not user friendly if my mom can't use it. Nobody wants to hold down CTRL to fill in a form.
So here it is: JFormFieldSQLCheckbox (Updated on 2015-06-24 after good points were made by Monica Bohanon (thanks :)))
How to use
- Download the file
- Add it to /libraries/joomla/form/fields to use it immediately, but since that is dirty practice place it somewhere safe and use something like JForm::addFieldPath(JPATH_COMPONENT . '/path/to/your/custom/fields'); in your code. For example in your com_your_component/com_your_component.php file.
- Use the Form Field in your XML: <field name="YOURNAME" type="sqlcheckbox" default="" label="YOURLABEL" query="SELECT id, title FROM #__YOURTABLE" key_field="id" value_field="title" multiple="true" />. Notice the multiple="true"? Not extremely necessary I guess, but use it!
- As with all Joomla's form fields that work with multiple values make sure you fix your component so it can save and read arrays, so explode the data when you read it and implode when you save it!
That's all folks!! Enjoy it! Feel free to contact us if something doesn't make sense :)