requiredEditFields
requiredEditFields(array $fields)
The requiredEditFields
method is an extension of the requiredFields
method, customized for the update form.
It verifies that the user has filled in certain fields during the update operation. The requiredEditFields
function
allows you to designate fields that are obligatory only when modifying existing entries.
It works like requiredFields but only for the edit form.
For example:
$crud->requiredEditFields(['first_name', 'last_name'])
Here's a full example:
$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->columns(['customerName','phone','addressLine1','creditLimit']);
$crud->displayAs('customerName', 'Name');
$crud->displayAs('contactLastName', 'Last Name');
$crud->requiredEditFields(['customerName', 'contactLastName', 'contactFirstName']);
$output = $crud->render();
In this example, if you try to update a customer without providing values for 'customerName', 'contactLastName', or 'contactFirstName', the form will alert you to fill in these fields.