views:

28

answers:

1

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  A: 

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)

anschauung
Hi thank you. I created the user account and that worked nicely. The problem now is '#action' property. Its being called instead of the submit (I was able to create the user account by removing '#action' -just testing, but eventually i need to put it back). So '#action' is being called instead of '#submit'. Is there anyway I can change the order so '#submit' is called first, then '#action'? Thank you!
berto77
You would need to edit the page where #action points, or override the #action with your own page that does the same things plus adds your custom code. What form are you trying to modify? There might be an easier way.
anschauung
I'm trying to modify the donations form. it has a url like this: donate/% (where % is replaced by a nodeid of the person to donate to).so donate/20 is donating to person 20. Its a simple form with the fields: currency and amount. I'm adding username/password/firstname/lastname/email...so I can collect some information on the donor. I tried putting the '#action' inside the '#submit', but that didn't work. thanks for your help.
berto77

related questions