Search code examples
phpdrupaldrupal-7drupal-modulesdrupal-fapi

drupal 7: Get user information on account creation


I am trying to create a module where the users creates his account and on submit, i get his information and insert them in a second database too. I mean that he will exist in both databases and in Drupals user table and in user table of the other database.

How can i get his information and insert them to a custom database?

I am totally new to Drupal development.

Thank you in advance for any help or advice.


Solution

  • You will need to implement hook_form_alter() and use the following code:

    function [YOUR_MODULE]_form_alter(&$form, &$form_state, $form_id)
    {
        if($form_id == "user_register_form")
        {
            $form['#submit'][] = "your_custom_submit_callback";
        }
    }
    

    Then create the custom submit callback to manipulate the submitted values the way you like:

    function your_custom_submit_callback($form, &$form_state)
    {
        // your code goes here...
    }
    

    Hope this works... Muhammad.