How to use hook alter form in module to register a user and also save some data in another table? - drupal

have a general idea on how to use hook alter to modify the feel of the registration form .
However the challenge I have is to not only have the user register, but to save some extra data into another table and then redirect user to a new page.
How would I get about doing that? Please help

Again, it'd be easier to plan what you're trying to do and take advantage of common solutions. I suspect what you're after is the Content Profile module.

add a custom function to your form, according to http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#submit-prop for more info
please notice the login page and the login block are different forms, with different form ids for your hook_form_alter.

Just implement hook_user(); when the first parameter is 'register', the registration form is being presented to a user, and the module can change it by adding new form fields (the module needs to return them to Drupal).

Related

Create moderation for form data

I want to add moderation logic for a form which has name, mail and comment. Now when anyone fills the form and clicks "submit" it should directly be posted to the page. I want to send the content to "admin" and to be published after the content is reviewed. How can I achieve this in Drupal? I'm using Drupal 7.2.
There are many ways to achieve what you want. I guess you are looking for a site-builder approach.
Then you may have a look at the Webform module. Webform lets you build forms and define e-mail addresses to where the submitted data should be send to.
Then there is the Rules module with which you can define a rule that on every form submission automatically a (initially unpublished) node is being created populated with the form values.
And finally you may provide a list of all unpublished nodes built with Views. Maybe you already provide a button "publish" next to each node in the list that triggers the node publication.
Alternatively you may also have a look at moderation modules like Workbench Moderation.
Or have a look at the Flag module which is pretty useful for flagging content according some logic and/or button clicks. For example you can add a flag: approved.

Add custom form data to Drupal module without using CCK fields

Iam very new to Drupal 7 so bear with me. I have created a jQueryUI drag and drop interface with JQueryUI tabs. My problem is i cant find the correct hook to add this custom interface to the admin interface. Like so (mockup) http://onlinemedia.rmcad.edu/sandBox/screenshot/screen-shot.jpg
All the examples I find are using CCK fields. CCK fields are great but they dont have this kind of custom functionality I want or does it?
Any help would very much be appreciated.
J
cck is drupal 6, not 7. to add to the node creation form you could use hook_form_alter or hook_form_ID_alter.
Check the form api documentation to get an idea of how to add stuff to the form object in either of those hooks.
From your mockup I understand you intend to add this drag&drop interface to a content-type.
If that's the case, I'd recommend you to add the appropriate fields first. Those would help storing the data in Drupal way, once the node is saved.
Once you are satisfied with the fields collecting the data you need, create a module and use hook_form_FORM_ID_alter hook to integrate your "interface", the presentation layer by altering those fields.
If you don't want to add CCK/Field components to store your data how about you create your own database table and store your custom data in there?
This approach is a long one but I have used it to great effect on a very big and complex project.
You will need a custom module with an install script which contains the details of your custom database table.
Forgive me but I don't remember the hook for altering a node-edit-form but that is where you input the code which implement your drag-'n'-drop elements.
Then, you could save the settings altogether when the node-edit form is submitted but I think it's probably better to implement some AJAX to save the settings to your custom database table. So, when a component is dropped into it's final resting place, you use AJAX to save that information to the database.
When a user comes back to edit that page, you simply load your custom settings and apply them to the drag-'n'-drop features and their previous configuration(s) would be visible to them.
I do hope that makes sense and it helps you.

Looking for ideas to implement an anonymous Suggestion Box in Drupal

I have a need to allow authenticated users to create content in Drupal anonymously. Ideally something like a Suggestion Box. The suggestion should have no fingerprint of who submitted it and ideally it should be submitted but not published until it is reviewed and approved.
Looking at the contact form and other modules, I haven't been able to get a clear direction on how to do this. Ideally I would think that at submission, I'd like to override the Authored By field and set this to anonymous. Is this the right direction or can I create a simple form that would be emailed to someone without ever creating a node?
I would suggest just creating a form using webform module.
If you don't want a node, just create a simple php form that sends a mail() on completion. You will need to enable the PHP filter and then just create a page with the PHP form in the content area.
If you wanted a node, you could create a custom content type called suggestions and then use a custom module to remove the author tag using hook_form_alter.
function uofm_usertasks_form_alter(&$form, &$form_state, $form_id) {
switch($form_id)
{
case 'suggestion_node_form':
$form['authored']['name']['#access'] = FALSE; // not sure if this is the right item in the form or not
break;
}
}

custom page in Drupal

hi i have created a website in drupal.In this registration page can be access by following url
http://mysite.com?q=user/register
But i want to make a custom page for registration.
Please give me some guide line , i don't have any idea for this
You want to modify the user registration form,
http://www.google.ca/search?client=safari&rls=en&q=user+registration+template+drupal&ie=UTF-8&oe=UTF-8&redir_esc=&ei=Jn0dTdTzI466sQP4uZ2PCg
a) hook_form_user_register_alter() documentation at http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_form_alter/6 b) if you totally cant do what you want with a happy little form altering then you can always hook_menu_alter() the page and use whatever page callback you desire instead of drupal_get_form.
Goto admin/build/modules
Enable Profile module
Add fields in profile and while adding a field make it 'visible during registration'

Require anonymous user to register to add content-type

How can I create a form that requires anonymous viewers to register in order to view it?
Right now, I've created a content-type (Submit Plan) which is a primary link available to everyone (anonymous + authenticated). I've restricted 'view' user permissions to anonymous users but they can still see the 'Title' input (I don't want that).
I'd like it so that when an anonymous user clicks on 'Adding a Plan' primary link (the Submit Plan content-type), it goes to the page and says:
"You must register for an account" OR
Redirects them to the registration page asking them to register to submit a plan.
I've been searching for a module or maybe some code to use but have come up short on this topic. Any help would be appreciated. Thanks!
If you're going to be redirecting users to the registration page, I'd strongly consider using something like logintoboggan to make the registration > node-creation process smooth. Otherwise, registration is a multi-step process and I'd imagine it being easy for users to lose their way back to the Add a Plan form in the process.
For the "show links or show the form" direction, there are at least two ways of approaching that: 1) create a custom page where you "import" the add_plan form (or show the links). 2) modify the node/add/plan page itself, either through themeing or the fapi (the forms api).
Here's a promising looking post for the first method: http://drupal.org/node/357895.
Here's a place to start with FAPI http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
Here's a post about theming the node form: http://11heavens.com/theming-the-node-form-in-Drupal-6
Without having tried this, I'd probably lean toward method one.
Update: just had another thought: you could also add the plan form to the registration form so they'd fill them out in one shot. I'm not sure of how to do that in general, but the node profile would work if they're only ever going to make one plan, and if not, you can look at how that's put together.
This can be done a few ways.
One, in your menu output, you can change the link to Submit Plan like this:
<?php
global $user;
if ($user->uid == 0) {
print 'Add a Plan';
} else {
print 'Add a Plan'l;
}
?>
The above code looks to see if the user object has a UID. 0 is anonymous, so that will print the link that sends them to register. Otherwise it will take them to the node add form for Submit Plan content type. This also assumes you control your own menu output. You can also override it in a similar manner by using a theme function.
There are a few ways you can do this, so start there and let me know what you think.

Resources