4

I have a situation where after doing the basic registration the user is redirected to a page where he needs to fill a small form.

I aim at implementing the hook_user_insert() and hook_menu() to do something like this

function registration_user_insert(&$edit, $account, $category){
  drupal_goto('splan/'.$edit['uid']);
}

function registration_menu() {
  $items['splan/%'] = array(
    'title' => 'Select a Plan',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('selectplan_form'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK
  );

  return $items;
}

In selectplan_form() I will define my new form and then, using the user ID, I would save data into user table.

The basic user registration form is being submitted, the user is redirected to splan/uid, but I also get the following error.

You are not authorized to access this page.

I have changed permissions to allow anonymous users to create and edit webform, but the problem still persists.

3
  • 1
    Why are you redirecting the user, instead of adding your form fields to the user profile form?
    – avpaderno
    Commented Apr 11, 2011 at 22:49
  • this situation is forced upon..i know i can add them in the user profile form but the requirements are not like that..
    – ayush
    Commented Apr 12, 2011 at 4:28
  • 2
    Then maybe a multi-step registration form instead?
    – Berdir
    Commented Apr 12, 2011 at 9:07

2 Answers 2

1

Implementing hook_user_insert() this way (calling drupal_goto() inside) is plain wrong:

  • if there are any other implementations of this hook in other modules meant to be called after yours, they will not get called at all
  • if for whatever reason hook_user_insert() from user module will not be called before your implementation, the user will not be saved at all
  • if you look at user_save() function in user.module, you'll see that after invoking 'insert' hook there are many other things this function is doing, so if you use drupal_goto(), they will not be done.

What you can do though is to add your own submit function to user_register_form, and in that function set $form_state['redirect'] to wherever you want (note that updating $form_state['redirect'] in hook_form_alter() will not work in this case, as user_register_submit() sets its own redirect, so you need to do it after this - hence the need for your own submit).

0

How about using the LoginToboggan module to create a temporary role for the user after signing up and giving that role the permissions needed?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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