0

I am new to Drupal 7 ( 1 month ) and have to do a rather complex task.

I have a content type (lets call it MyContent) for which i tried to create a custom form (I imported the fields from the original add content form in my own custom module generated page) which contains, among other fields, an email field, and i need to add 1 more field called password. With these 2 fields , i want on form submit:

*IF the email & password combination does not already exist

-> first create a user account taking the email as username and password as password ,
-> then create the content(disabled),
-> then make the site visitor confirm his email to enable his account
-> and after validation make the content viewable by all

*IF the email&password combination exists then :

-> create the content viewable

all of this by clicking one button. The general ideea is that i want visitors, who are not logged, to be able to create content but in the process , get a user account generated as well. Also if the visitor already has an account then the email&password will work as a validator for letting the user create more content.

Is it even posible? I saw that Drupal has a lot of configurable options for users but nothing close to such a crazy ideea.

0

All of this is possible, but you will need to write a bit more code for it to work.

First, I suggest you use LoginToboggan. LT provides a workflow for validating a user's email address which you can hook into either by code or perhaps with the Rules module. LT already has the framework for tracking if a user is verified or not. It will be up to you to write the code to create the user (not too hard) and to create the node as published or unpublished depending on the status of the user.

Second, you will have to decide what to do for verification (what if they enter the right email but wrong password?).

| improve this answer | |
  • thanks for the answer. My worry is that i can't control the order of the submit ( as in first create user then content) since I imported the form for add new content from the original page. Can i trigger the validation before the submit process using hook_node_submit ? – Cristi Jul 10 '14 at 19:04
  • Drupal's Form API helps you control this somewhat. In your form_alter(), you can add something to the $form['#validate'] function, which will run (and can modify form values) before the submit functions are executed. Furthermore, you can make sure that your function is run first in the #submit group by using the PHP function array_unshift() to list your submit function first. You should definitely read up on the Form API. – coreyp_1 Jul 10 '14 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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