I would like for an anonymous user to be able to send the node author a private message directly from the node page. Is this possible with private message, 7.x branch?

This would function exactly like here:
http://charlotte.ebayclassifieds.com/retail-merchandise/charlotte/sphinx... (click on 'reply by email' to see the form)

If this is possible, please help me understand how to implement it? If not, perhaps change this to a feature request?

Also, if anyone has recommendations on another way to achieve this, I am open to suggestions.

Thanks!

Comments

Gastonia’s picture

I guess I should clarify the above. I know a link is available to be displayed on the node form that will take you to the pm form.

But I am trying hard to keep the person on the page of the node. I don't want to redirect them. This seems like it should be default functionality, especially if a link can be put on the page, then why not a block with the exact form that displays after clicking the 'send author?' link?

Or, is there a way to pop that form up into Drupal 7's new lightbox overlay system? I am toying with the idea of using the 'send author' link for the source and putting it in an iframe. Surely there is a better way?

dhayles’s picture

I to would also like this feature, I have Commerce Nodes whereby each product node could have been created by a differing user.

I would like to have on the page which is displaying the product node the message form which has the TO: UID pre-populated from the node owner, a couple of Line items that can populate into the message body and a blank message field also to be added to the message body.

The send button would also reside on this page.

Any help would be greatly appreciated.

lameei’s picture

alex.87’s picture

#3 doesnt work in d7 im getting errors and output is just array...

Gastonia’s picture

It's been a while since I posted that, but I have an early drupal 7 snippet that still works.

To enable it, you simply create a block that can execute PHP. Paste this into the block, although, you may have to tweak it for your specific use.

<?php
$node = menu_get_object();

//if person is logged in....
if ($node->uid != 0) {
  module_load_include('pages.inc','privatemsg');
  $recipients = $node->uid;
  print "<div>Contact " . $node->name ." about this post.</div>";
  $subject = $node->title ." question.";
  $form = drupal_get_form('privatemsg_new', $recipients, $subject);
  // Setup destination parameter to be equal to current page.
  $form['#action'] = url('messages/new/'. $node->uid, array ('query' => drupal_get_destination()));
  print drupal_render($form);
drupal_set_title($node->title);
}

//text to display if person is not logged in
if($node->uid == 0) {
print "<div>Please login to contact this seller.</div>";
}

?>

I have in my notes where I was working on submitting the form via ajax, however, I never finished implementing it. If anyone tinkers with it and gets it working, please post your code! I think that would be great functionality.

alex.87’s picture

Thanks for your snipet Gastonia, i had problem to show div if user is not logged in, so i edited your codee a bit and got it working like this:

<?php
global $user;
if ($user->uid) {
    module_load_include('pages.inc','privatemsg');
    $recipients = $node->uid;
    print "<div>Contact " . $node->name ."  about this post.</div>";
    $subject = $node->title ." question.";
    $form = drupal_get_form('privatemsg_new', $recipients, $subject);
    // Setup destination parameter to be equal to current page.
    $form['#action'] = url('messages/new/'. $node->uid, array ('query' => drupal_get_destination()));
    print drupal_render($form);
    drupal_set_title($node->title);
} else {
    print "<div>Please login to contact this seller.</div>";
}
?>
ptmkenny’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Thanks @Gastonia and @ul71m0. I've added this to the privatemsg documentation here.

pascalli’s picture

HI All,

I've tried your solution in #6.
I created a block as suggested. Added php code and eval.
PM Form appears but default value are not filled in.

error:
Notice: Undefined variable: node in eval() (line 5 of /Users/pascallisot/Sites/student.be/modules/php/php.module(80) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 5 of /Users/pascallisot/Sites/student.be/modules/php/php.module(80) : eval()'d code).
Notice: Undefined variable: node in eval() (line 6 of /Users/pascallisot/Sites/student.be/modules/php/php.module(80) : eval()'d code).

Any idea where I need to check?

Thx in advance for your time.

Pascalli

pascalli’s picture

Hi All,

It's me again. Please disregard my previous comment.

Found issue.

By putting code in template node value can be reached.

Works fine now.

Cheers,

Pascal

xiaomo’s picture

I know this is an old post but how did you get #6 working? I'm getting errors.

xiaomo’s picture

Status: Closed (fixed) » Active
xiaomo’s picture

Status: Active » Closed (fixed)