The fact that you can update any drupal form via hook_form_alter is very well known and popular thing. But what to do if we want to add an additional validation rules for the particular form? Something like function hook_validation_alter does not exists in Drupal and the hook_validate only works for node forms. Fortunately, there is an option, a bit hidden though. Therefore I would like to share the knowledge which took me a while to earn.
The trick is to add following line into the hook_form_alter:
$form['#validate'][] = 'your_validation_function';
This way you can define an array of additional validation functions. Make sure you report all validation errors using the form_set_error() function.
pošli do vybrali.sme.sk
Post new comment