0

I am using Private message as PHP in a block on the node of a page so that a person can contact the node author without having to leave the page. Here is the code:

$node = menu_get_object();
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.";
  print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
}

However, Private message hijacks the title of the entire page, and now every single node value is 'Write so-and-so' a new message, instead of what the page title should actually be.

Thoughts on how to correct this?

You can check out what's happening here on the test server:

http://g.hokkaido-select.com/classifieds/cars-and-vehicles/motorcycles-and-scooters/2006-150cc-scooter (note, you have to be logged into see the block, but the page title error can still be seen)

1 Answer 1

2

I guess the private message form sets the title directly. A simple way round it might be to cache the current title before you render the form, then set it back again afterwards:

$stored_title = drupal_set_title();
print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
drupal_set_title($stored_title);
1
  • drupal_set_title was the function I needed. It sets it in the privatemsg_new function: drupalcontrib.org/api/drupal/…. Tangent question. You'll notice towards the bottom that if the $_REQUEST['destination'] field is empty, it simply redirects to 'message' after submission. Redirection would work correctly back to the node page if I could set that url variable, but I have a scope issue. In PHP is there a way to set that from outside the function?
    – blue928
    Commented Jul 17, 2012 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.