0

So, I have a user's profile page where there is a Message button. When I click the message button it should redirect me to a custom page with a form in it. How can I get the user ID from the profile page I visited in order to know where to send the message?

1
  • can you control the link of the message button?
    – Alex
    Commented Jul 27, 2015 at 8:38

2 Answers 2

3

The easiest way would be to add the user id as a ref argument to the form url in your message button, on the user profile page:

<a href="/path/to/custom/form?userid=<?php print arg(1); ?>">go to custom form</a>

Then, on your custom form:

$args = drupal_get_query_parameters();
$userid = (isset($args['userid']) ? $args['userid'] : false);
1
  • Yes, this is the solution I used in the end. I hoped that it would exist some drupal functionality for that.. Thanks!
    – mihai
    Commented Jul 27, 2015 at 9:05
0

You can access the user id from the URL of user profile page. The url will be like /user/userid. You can access it by arg(1).

Hope this helps..

2
  • Yes, I know that. What I need is the ID when the user has moved to the message page; which is a different page than the profile page.
    – mihai
    Commented Jul 27, 2015 at 6:59
  • You can pass that through url, or you can save the id using variable_set() in user profile page and access it in message page using variable_get().
    – Abin
    Commented Jul 27, 2015 at 7:22

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.