requiredFields

requiredFields(array $fields)

A common validation for pretty much all the forms is the validation of required fields. Use the requiredFields method to add all the fields that are required. By adding a field as required you are getting:

  1. An asterisk at the left of the name so the user can understand that this field is required
  2. A client side validation for the required field. That means that you will get a prompt that this field is required before even the data is sent to the server
  3. A server side validation in case the client side was skipped for any reason

The syntax is simple, you just need to add the field names from the database that are required. For example:

$crud->requiredFields(['first_name', 'last_name'])

You can see a full working example below:

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->columns(['customerName','phone','addressLine1','creditLimit']);

$crud->requiredFields(['customerName', 'contactLastName', 'contactFirstName']);

$output = $crud->render();

You can see live the required fields if you try to add or edit any row and save the form without a value for either one of the 3 required fields