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?
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);