1

I have a form on my website and i would like the page to check if the user is logged in, if they aren't, then redirect them to a login page, if they are, then show the form.

When they are submitting the form, how can I get that users username and get that review that they submitted show up on their account?

If you need any more details just comment.

I am using Drupal 7

1
  • is it drupal 6 or 7 ?
    – GoodSp33d
    Jun 24, 2012 at 12:13

3 Answers 3

1
  1. First make sure only users with a specific role can access this form. You can use the #access property to restrict the access to a specific form.
  2. The LoginToboggan module can redirect the user to the login page if they get an access denied.
  3. In the submit hanlder of your form you can access the current user by adding global $user at the top of your method.
1

Assuming 6.
You can use global variable $user to check if the user is anonymous or authenticated. If authenticated the same variable will also hold username and loads of other information.

In foo_bar_form()

global $user;
if($user->uid == 0){
// Anonymous user redirect to login page
}

In foo_bar_form_submit()

global $user;
// To get user name
$user_name = $user->name;

You need to create a flag(profile_value perhaps) and update this when a user submits. So that next user logs into the application you need to check for this flag if set or not and proceed accordingly.

1
  • What changes would I make for my system? It is drupal 7. Sorry I just updated then I was posting quickly.
    – Amar H-V
    Jun 27, 2012 at 6:15
0

I think we need several more details. When you say "the review that they submitted," what kind of entity are you talking about? Is a review a node? A comment? Something to do with a custom module like fivestar?

Whatever it is, BetaRide is right about LoginToboggan; if you can restrict the creation of these reviews to authenticated users, then you can use LT to redirect them to log in if they attempt to create one as an anonymous user.

As for "showing up on their account," that also requires more details, but once you've made the user the author of whatever entity is serving as your review, chances are you can use a view to generate a list of reviews created by a particular user and display that on the user's profile page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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