drupalhook-form-alter

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()?


Solution

  • 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.