0

I'm encountering an issue tying in a #validate hook into the Drupal registration form. In a custom module, I have a call to the User Register form (the form that is used on Account Creation) and an addition to #validate that should run an outside validation function.

/**
 * Implements hook_form_FORM_ID_alter()
 * Form ID: user_register_form
 */
function mymodule_form_user_register_form_alter($form, &$form_state) {
  $form['#validate'][] = "mymodule_validate_register_form";
}

function mymodule_validate_register_form($form, &$form_state) {
  //validation code
}

And on running a dpm of the Register Form, the validate statement is in place. However, it appears that the functions is never being run.

When I look at the #validate array, its the last option, predated by user_account_form_validate, user_validate_picture, and user_register_validate. Is it possible that its never being run due to the order of the other validate statements, or is there something wrong in my logic? Are there other approaches to validating the data during User Registration over the hook_form_FORMID_alter function?

1

This:

function mymodule_form_user_register_form_alter($form, &$form_state) {

needs to be this:

function mymodule_form_user_register_form_alter(&$form, &$form_state) {

Notice $form is by reference in the second snippet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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