In this tutorial, we'll cover how to add a checkbox to your forms. This method allows you to integrate checkbox inputs seamlessly into your application forms. Additionally, we will demonstrate how to configure the checkbox to read its option data from a field in a database using the childDatabase
method. This method adds a checkbox input field to your form, taking three parameters:
To configure the checkbox to read its option data from a field in a database, you can chain the childDatabase
method after the checkbox
method. This example shows how to add a checkbox that retrieves its options from a database table.
// Adding a checkbox with options from the database
$objConfig->checkbox('field_name', 'field_label', $required = 0)->childDatabase('table_name', 'id_field', 'value_field');
In this example:
For the configuration to work properly, it's important to include the 'field_name'
amongst the `addFields` and `editFields`
. This ensures that the fields are correctly initialized and integrated into your form. This example shows how to configure the add and edit fields.
// Adding your checkbox field to the add and edit forms
$objConfig->addFields(array('field_name'));
$objConfig->editFields(array('field_name'));
By following these steps, you can easily integrate checkbox fields to read its option data from a field in a database using $objConfig->checkbox('field_name', 'field_label', $required = 0)->childDatabase('table_name', 'id_field', 'value_field');
.
Your download is here.