Validating user input on the client side
We need to be sure our users provide the right information when they’re filling in a form. The sooner we communicate to the user an issue in the data, the better the user experience. That is why we want to check the errors even before the user sends the form to Joomla!. This is why we use client-side validation for our forms.
When using Joomla! standard form fields, there are some attributes we can use in our fields that will add validation to our forms out of the box. For instance, when we set the required
attribute in the XML definition for our form field, the user will need to include data to send the form.
Let’s add some validation to our Client edit form. So in the src/component/admin/forms/client.xml
file, replace the email
field definition with this code:
<field name="email" type="email" required="true" ...