Start Validating html file

Validating html file

The method will return a boolean value indicating whether the validation succeeded or not.

For example the inline validator above could be moved into new components/validators/Country Validator class.

If you want your validator to support validating a value without a model, you should also override yii\validators\Validator::validate().

validating email addresses), you may call the validate() method of the desired validator, like the following: After validation, you can check if the validation succeeded or not by calling the has Errors() method, and then get the validation errors from the errors property, like you do with a normal model.

You may also access the dynamic attributes defined through the model instance, e.g., .

For this reason, you should always perform server-side validation by calling yii\base\Model::validate(), as described in the previous subsections.

Behind the scene, yii\widgets\Active Form will read the validation rules declared in the model and generate appropriate Java Script code for validators that support client-side validation.

When yii\base\Model::validate() is called, it will call two methods that you may override to customize the validation process: To validate attributes only when certain conditions apply, e.g.

the validation of one attribute depends on the value of another attribute you can use the when property to define such conditions. The following examples shows how to trim the spaces in the inputs and turn empty inputs into nulls by using the trim and default core validators: You may also use the more general filter validator to perform more complex data filtering.

For example, If you also need to support client-side conditional validation, you should configure the when Client property which takes a string representing a Java Script function whose return value determines whether to apply the rule or not. As you can see, these validation rules do not really validate the inputs.

Instead, they will process the values and save them back to the attributes being validated.

Below are some examples: Note: By default, inline validators will not be applied if their associated attributes receive empty inputs or if they have already failed some validation rules.