0

Drupal 7 comes with the built-in user registration form (user/register). I use this form for new users to register. Which is quite obvious. Now the problem is, and I find it hard to believe that it isn't there, I need some validating.

When a new user completes the form and hits submit, the account is being created. Good.

But: when a user completes the form and hits submit, but the email address or username is already in use, the pages just reloads and the user is not being created, which is good, but theres no warning on what he has to change in the form what so ever.

I find it strange that this is not standard.

Could anyone provide me some help? I really have no clue...

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Tim Reynaert
  • 145
  • 5
  • 19

1 Answers1

2

Use can achieve that with many approaches.

Here's an example using hook_form_alter()

function [YOUR_MODULE]_form_alter(&$form, &$form_state, $form_id)
{
    if($form_id == "user_register_form" || $form_id == "user_profile_form")
    {
        $form['#validate'][] = '_your_custom_validation_callback';
    }
}

function _your_custom_validation_callback(&$form_state)
{
    // use your validation code...
}

Hope this works... Muhammad.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105