Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After submit action in form_alter

i need to insert data in my tables after user creation. I think to use hook_form_alter() for $form_id == "user_register" but I don't know how to say "after you created user, do this."

How can I do it in hook_form_alter()?

like image 801
Cris Avatar asked Dec 03 '22 09:12

Cris


1 Answers

You can add custom submit handler to forms like this.

function hook_form_user_register_alter(&$form, &$form_state) {
    // ...
    $form['#submit'][] = 'yourModule_user_register_submit';
}

function yourModule_user_register_submit($form, &$form_state) {
    // do what you want to do after registration
}

I'd also recommend to use Drupal's Triggers & Actions to achieve this. AFAIK there was a bug with one of the triggers that fire after user registration. Don't know if that has been fixed.

like image 74
rik Avatar answered Jan 11 '23 16:01

rik