2

I have created an entry form. Only authenticated user can access it. I have created a menu link for it and if any anonymous user clicks on menu link I want to show a login form and after successful login user is redirected to that entry form. I don't want to hide the menu link from anonymous user.(I have about 5 to 6 forms with same condition)

8

Logintoboggan will allow you display a login form when a user hits an access denied page:

Provide a login form on Access Denied pages for non-logged-in (anonymous) users.

0

?php
          global $user;
          //Redirect original Page
          $redirect = 'destination='.drupal_get_path_alias(substr(urldecode(  drupal_get_destination()), 12) );
          if ($user->uid) 
          {
                        header('Location:?q=node/nodename');   //If user is logged in. Go to specific destination      
          }
         else 
          { 
          //If user is not logged in. Show him login or register
                       $login_link = l(t('Login'), 'user', array( 'query' => $redirect, 'alias' => TRUE )); 
$register_link = l(t('Register'), 'user/register', array( 'query' => $redirect, 'alias' => TRUE ));
$user_utilities = '

' . $login_link . '
' . $register_link; } echo "You are not Registered User. Please Login "; return $user_utilities; ?>

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.