1

I am trying to add a custom validation function to an existing form. I am using hook_form_FORM_ID_alter() to edit the form. I am then adding a new function to the #validation array. When I use dpm() and print out $form['#validation'] I can see that my function is there. However the validation step is not running. If I dpm() in the validation function it is not hit.

/**
 *  Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_mycustomdorm_form_alter(&$form, &$form_state, $form_id) {
    $form['#validate'][] = 'mymodule_test';
    dpm($form['#validate']);       
}

function mymodule_test($form, &$form_state) {
  dpm($form_state);
}
4
  • Have you cleared the caches since adding the hook function?
    – Clive
    Jan 20, 2015 at 16:49
  • @Clive first thing I do when something is not working. No joy.
    – Bobby
    Jan 20, 2015 at 16:54
  • 1
    @DEVARAJJOHNSON Please don't edit questions to modify people's code - it makes it impossible to answer the question. Thanks
    – Clive
    Jan 20, 2015 at 17:49
  • Are you sure that "mycustomdorm_form" is right? Is it your FORM_ID?
    – arrubiu
    Jan 20, 2015 at 18:24

1 Answer 1

0

Hi Bobby you can use custom validate submit handler to deal with this

$form['submit']['#validate'][] = 'custom_validate_function'

all you have to use is #validate in submit handler.

use the same callback function as above with replacing the callback name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.