tags:

views:

28

answers:

2

Hi

I have created a form using add new content type and cck fields. I want anonymous users to view the menu item to this form but not the content. So when users click on the link they should get redirected to login page. I have granted the permissions of access all content. Any suggestions please.

Thanks Kanwal

A: 

create node-{YOURCONTENTTYPE}.tpl.php in your theme, then write next code:

<?php
global $user;
if (!$user->uid) {
  drupal_set_message('You should login before see this content type');
  drupal_goto('user');
}
?>
//HERE CODE FROM STANDARD node.tpl.php of your theme
Nikit
Thanks a ton nikit....i finished it....
Kanwal
Be careful with this - I attempted something similar once and it broke search indexing - when cron ran it failed the test and was redirected. I think it broke everything else that ran on cron too.
Andrew
Yes, it was fast solution, you may fix it via checking running script $_SERVER['SCRIPT_NAME'] != '/cron.php'. Best solution is using Rules module, that will check permissions...
Nikit
A: 

I would never use the theme layer for access control and redirection, as Nikit suggests.

You could simply create a normal menu link to 'user/login' with "Create content" as menu title. Drupal will automatically hide it when you're logged in.

An even better option, IMHO, is to use the Inline Registration module. As the module page says: "Inline Registration allows anonymous users to register via the node/add page, thus removing a step/barrier from the user actually publishing content." Try it, I think it's a huge usability improvement.

marcvangend
Thanks mate. Inline Registration is not working for me because its still showing the form but i have used the user/login way. Now the only problem is that it is not showing the message that "You should be logged in before seeing this content". Is there any way to do that. If not then also it is fine with me. Thanks again
Kanwal
What I would do, is make your menu item link to `user/login?destination=node/add/page` (replace 'page' with your content type) so the user is redirected to the node form after login. Next step: in a custom module, implement hook_boot(), check `if ($_GET['destination'] == 'node/add/page')` and do a drupal_set_message().
marcvangend

related questions