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?

  • can you control the link of the message button? – Alex Jul 27 '15 at 8:38
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);
  • Yes, this is the solution I used in the end. I hoped that it would exist some drupal functionality for that.. Thanks! – mihai Jul 27 '15 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..

  • 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 Jul 27 '15 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 Jul 27 '15 at 7:22

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.