Special field name

Validating field with special name

When using FormValidation with some server-side frameworks such as CakePHP, Symfony, Rails, Spring, etc, there is a relationship between the model name and the name attribute of input.

For example, assuming that an user is modeled by User class with firstName, lastName, username, emails[] properties.

Following the naming convention defined by these frameworks, the inputs in the form of adding new user might have the name attribute such as:










When using FormValidation to validate these kind of fields, you must wrap the field name between single or double quote as following:


FormValidation.formValidation(
    form,
    {
        fields: {
            'user[firstName]': {
                validators: {
                    ...
                }
            },
            'user[lastName]': {
                validators: {
                    ...
                }
            },
            'user[emails][]': {
                validators: {
                    ...
                }
            },
        },
    }
);

Below is a sample example: