I'm trying to make a "Message Me" link on all the user pages, and and trying to show it in the form of a block. I used this to add a block on all the user pages:

   if ($node->uid == $user->uid) {
      print l('Send me a message',"privatemsg/msgto/".$user->uid);
}

Right now when i click on that link, it takes me to the "write a new message" page. Is there a way or is there some kind of code that i could add to my block so that when i click on the link, it autofills the "To: " field with the user's name that I clicked the link from? Example if i click on the "Message me" link on Bob's user page, the "To:" field would be autofilled with "Bob".

thanks in advance for any type of help.

Comments

rszrama’s picture

It should auto fill in the "To" field if you've got a correct URL (/privatemsg/msgto/34). My hunch is there is no user ID on the end of your URL... unless this was something that only made it in the latest version. I'd check out the URLs for the link to see if it's getting formed correctly. I don't know why you'd have a user message themselves, which is what your code does now. And if you haven't added global $user; to the code you would always get 0 for $user->uid. Check those things and get back if you can't figure it out.

Glowingtree’s picture

the simple answer:

just put this in the user_profile.tpl.php file or custom block....

<?php print l('Send me a message',"privatemsg/msgto/".$user->uid); ?>

$user->uid is already referring to the owner of the user_profile.tpl.php page regardless
of the logged in user - good enough solution for starters, though
users would still have it on their own page - However on top of this you could do a simple " if - else"
statement... otherwise known as the "vise-versa"

        
  if  ($user->uid != ($GLOBALS['user']->uid) )
        
         { print l('Send This User a Private Message',"privatemsg/msgto/".$user->uid); }

         elseif ( $user->uid == ($GLOBALS['user']->uid) ) 
        
         { print ('') ; }

and I actually tried it! It actually worked! (Drupal 5.7)

And of course, you would want to put in some DIVs in proper place so you can give it a CSS class
(not sure about syntax for conditional printing of html tags, the " " to give it a class would kill the link syntax, unless of course
you just put a div around the whole thing, but then you would have a styled box whether a link appears or not.. hmmm)

berdir’s picture

Status: Active » Closed (won't fix)

Sorry for pinging the participants, I am closing old issues.

This version of Privatemsg is not supported anymore, maybe it is already implemented in Privatemsg for Drupal 6 and if not, you are welcome to open a new issue for it.