How to get the user ID from the last profile page?
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:

&lt;a href="/path/to/custom/form?userid=&lt;?php print arg(1); ?&gt;"&gt;go to custom form&lt;/a&gt;


Then, on your custom form:

$args = drupal_get_query_parameters();
$userid = (isset($args['userid']) ? $args['userid'] : false);