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 '<a href="/user/register">Add a Plan</a>';
} else {
print '<a href="/node/add/submit-plan">Add a Plan</a>'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.
精彩评论