Silently create a user account when another form is submitted

240 views Asked by At

I have a form created from another module. I want to add 2 fields to that form: 1. email, 2. password. I think I can do this with hook_form_alter. Then I would like to create a user account and log the user in when the submit button is clicked, then go ahead and execute the action defined by the form.

The original form doesn't have a #submit property...it just has a #action property.

I add the #submit property like this: $form['#submit'] = array('accesscustom_submit');

but accesscustom_submit doesn't seem to be getting called. I think the form is just getting redirected to the #action url that's already defined. Any ideas?

1

There are 1 answers

3
anschauung On BEST ANSWER

Are you trying to edit the comment form? $form['#action'] is a pretty rare property ... the comment form is the only one I can think of that uses it.

In any case, you can create an account pretty easily by settings up a user array ($account = array('name' => $username, 'pass' => $pass)) and sending it to user_save. See http://api.drupal.org/api/function/user_save/6 for more details.

Once the account is created, you can call user_external_login to log them in (http://api.drupal.org/api/function/user_external_login/6)