SEM Labs

Handcrafted Pixels, Code & Title Tags

Error Handeling

XFL

When XFL validation elements (collection, file and validate) do not pass validation an error is added to an error array in the XFL class. When there are errors in the error array, the parser does not go into the submit state. This allows you to report the errors.

The error array can be accessed through the $errors class variable in the XFL class.

Defined and Generic Errors

You have the option to supply an error attribute to each validation element. This error will be added to the error array when the validator fails to validate.

When the validator fails to validate in the above example, the error 'Please give your name' will be added to the error array.

If no error attribute is defined, a generic error will be created using the name attribute of the validator's parent element and a generic prefix. In the case of multi-dimensional field names, the last part of the name that is not an integer will be used. In the above example, where the field's name is 'company[name]', the 'name' part will be used in the error. A generic prefix will be append to this. By default the generic prefix is 'is invalid'. So the resulting generic error for the above example would be, 'Name is invalid'.

You can change the generic error by setting the $genericErrorPrefix class variable in the XFL class.

Adding Classes to Erroneous Elements

When a validator element does not validate, XFL can add a class to the validator's parent element. This is done by setting the $errorClassName class variable in the XFL class.

This will add the class to erroneous fields like so: