In this example, we will create an ordinary login form, with login, password, and password confirmation fields.
We'll start with defining a schema. It's an object with three keys, representing our fields. Each of them has the following self-explanatory properties:
When the schema is ready, our next step is to provide a way to check if the values received from our form are correct. In order to do so, we prepare a validation function. That function, called validator, takes a model (the submitted object) as input and throws an error whether any value doesn't meet given criteria.
In our case we say 'form is invalid' when there's no login or password at all, login has less then 5 characters, password has lass then 10 characters or given passwords mismatch:
Now that both have the schema and the validator, we can define our bridge, which will be a binder between the form and the data itself.
All we have to do is to extend
Bridge class and implement its methods according to the Bridge concept:
After our custom bridge is created, we can use in the very same way as we would use predefined one - we have to supply the schema and validator and then we can take an advantage of it in the AutoForm: