This project is not covered by Drupal’s security advisory policy.

Validations extends Forms API to add validation procedures, which should minimize the use of custom validation functions.

Currently, it has server-side (i.e. PHP) validations, but will be extended to provide client-side (i.e. JavaScript) validations as well.

Checks included:

  • Type: number, integer, float
  • Min and max number values
  • Min and max selected options (checkboxes and select fields)
  • Min and max string length
  • Valid dates
  • E-mail fields
  • URL fields
  • Regular expressions
  • Custom validation callback functions
  • Require a filed if another field is equal to, different to, greater or lower than a certain value

You can also set your custom global error messages for each validation type in the settings page, but can provide a specific message for any field while building the form, overriding the general settings.

As said, this does not include JavaScript validations for now, but will shortly.

An example of usage follows (note the new '#validations' element):

$form['field'] = array(
       '#type' => 'textfield',
       '#title' => t("A test fied"),
       '#validations' = array(
               'type' => float,
               'min' => 0,
               'max' => 32,
               'callback' => 'callback_function', // arity: ($form, $form_state, $field_name)
               'required-if' => 'other_field!=3', // supported =, ==, !=, <, >, <= and >=. Value can be empty.
       ),
);

I hope this is will serve as a kick-off for a stronger proposal for a validations framework which could possibly include CCK validations.

WARNING: this module is not ready for production use. This is here now to receive feedback, but be warned many features might be changed before it reaches version 1.0

Project information

Releases