In this tutorial, we'll cover how to add a checkbox to your forms. Additionally, we will demonstrate how to configure the checkbox to read its option data from an array using the childArray
method. This method adds a checkbox input field to your form, taking three parameters:
To configure the checkbox to read its option data from an array, you can chain the childArray
method after the checkbox
method. This example shows how to add a checkbox that retrieves its options from an array.
// Adding a checkbox with options from the array
$objConfig->checkbox('field_name', 'field_label', $required = 0)->childArray($data);
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 checkbox 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 into your forms using $objConfig->checkbox('field_name', 'field_label', $required = 0);
. We also covered how to configure the checkbox to read its option data from an array using $objConfig->checkbox('field_name', 'field_label', $required = 0)->childArray($data);
.
Your download is here.