[development] How to add user role during registration with custom form
leerowlands at rowlands-bcs.com
Fri Feb 26 22:13:30 UTC 2010
Have a look at autoassignrole module.
It does just this, you can also patch profile_role so the two integrate and
you get custom registration fields per url/role.
From: development-bounces at drupal.org [mailto:development-bounces at drupal.org]
On Behalf Of Steve Edwards
Sent: Saturday, 27 February 2010 7:49 AM
To: Drupal Development
Subject: [development] How to add user role during registration with custom
I took over a site that uses a custom registration form that directly calls
user_register_submit directly, and I need to have a user role added to this
user when this form is submitted. However, I can't add the value to
$form_state['values']['roles'] because the function errors out if there is a
roles array because it is seen as a 'malicious attempt to alter protected
user fields.' Since that function then calls user_save, it seems that once
the user is saved, I need to 1) load the user I just created, 2) add the
role to the object, and 3) save it again. However, in order to call
user_load, I need the uid, which isn't returned from user_register_submit.
The only logical thing I can think to do is query the users table with the
user name I just created (entered as part of the form), get the rid, and
then call user_load and do my thing.
Is there a better (and easier) way to do this that I'm missing, or am I on
the right track?
Internal Virus Database is out of date.
Checked by AVG - www.avg.com
Version: 8.5.406 / Virus Database: 271.1.1/2686 - Release Date: 02/13/10
More information about the development