Form element based validation library for Drupal FAPI.

To implement an existing form helper validation rule add the desired 'form_helper_validation_validate_element_RULE_TYPE' function name to an element's '#element_validate' array.

<?php
 // This element's value would now have to be a valid email address.
$form['mail']['#element_value'][] = 'form_helper_validation_validate_element_email';
?>

If the form element's name contains a validation rule delimited by an underscore, one can just call 'form_helper_validation_validate_element_name' which will figure out the correct validation rule.

<?php
 // This element uses the 'phone' validation rule because the element's name is home_phone.
// The word 'phone' matches an existing validation rule.
$form['home_phone']['#element_value'][] = 'form_helper_validation_validate_element_name';
?>

Validation rules include:

  • Strings
    • alphanumeric
    • words
    • phone
    • zip
    • ssn
    • email
  • Numbers
    • numeric
    • float
    • bit
    • min
    • max
    • range
  • Dates
    • date
    • time
    • datetime
  • URLs
    • url
    • path
    • domain
    • extensions
  • Regular Expressions
    • regex
Module developers can implement custom validations rules by calling form_helper_validation_validate_element($rule, $element, &$form_state) and passing a custom validation rule. The form helper validation demo has a working example called form_helper_validation_demo_custom_validation_rule($element, &$form_state). Developers may be better off building DIY element_validate functions.

Note

  • There are SimpleTests for every validation rule so that old validation rules can be improved and new ones added with breaking existing implementations.
Resources Similar modules:
  • Validation API - Provides a UI to implement validation rules which are store in the database. (Active Development)
  • CCK and Webform - Provide custom validation rules intergrated with most of their form elements.
  • Validations

Functions

NameDescription
form_helper_validation_has_ruleCheck if validation rule exists
form_helper_validation_menuImplementation of hook_menu().
form_helper_validation_permImplementation of hook_perm().
form_helper_validation_validateExecute validatation for a specified rule type
form_helper_validation_validate_elementExecute element validation for any rule including custom rules for other modules.
form_helper_validation_validate_element_nameValidate element based on a rule type defined within the element's name.
_form_helper_validation_get_ruleGet validation rule
_form_helper_validation_get_rulesGet validation rules
_form_helper_validation_validateValidation rule handler for regular expression validation or a custom validation function.
_form_helper_validation_validate_dateValidation rule for US date
_form_helper_validation_validate_datetimeValidation rule for date and time
_form_helper_validation_validate_elementExecute element validatation for a rule type
_form_helper_validation_validate_emailValidation rule for e-mail address
_form_helper_validation_validate_extensionsValidation rule for file extensions
_form_helper_validation_validate_maxValidation rule for maximum number
_form_helper_validation_validate_minValidation rule for minimum number
_form_helper_validation_validate_pathValidation rule for path
_form_helper_validation_validate_rangeValidation rule for number range
_form_helper_validation_validate_regexValidation rule for custom regular expression
_form_helper_validation_validate_timeValidation rule for time
_form_helper_validation_validate_urlValidation rule for url
_form_helper_validation_validate_wordsValidation rule for number of words