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?
2 Answers
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!– mihaiCommented Jul 27, 2015 at 9:05
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.– mihaiCommented 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().– AbinCommented Jul 27, 2015 at 7:22