Drupal 7 validating form on ajax

You need to add your validation function to that array by adding the following: $form['#validate'][] = ‘starting_drupal_dev_form_validate’.$form[‘validate’] is an array and you can add to that with $form['#validate'][].

The second invalid title is “birds of a feather flock together”. It appears that you have the function custom_form_validate($form, &$form_state) nested inside MEIN_MODUL_form_alter(). Would this be usable to deal with verifying whether a user has previously submitted a form on a specific node?

In the validation function, you need to check the value of the title field, which is held in $form_state[‘values’][’title’].

If the value is “the quick fox jumped over the lazy dog” then set an error. The first parameter is the name of the field that has caused the error. The field specified will be highlighted with a red border, so the user has a clear visual cue as to which field has not validated.

You will then see an array with data from the form you just submitted.

We are interested in the values that the user adds to the form, which is held in $form_state[‘values’].

Leave a Reply