HowTo: Integrate Privatemsg with the Flag and jQuery_Impromptu modules

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

I needed a way for a user to be prompted to send a message to the author of a node after it was flagged. This was my solution.

jQuery Impromptu provides a nice way of implementing a pop-up feature.
Flag of course flags a node.

  // Load necessary to avoid error
  module_load_include('pages.inc','privatemsg');

  // Adds javascript to header
  jquery_impromptu_add();

  // Gets rid of whitespaces that break javascript code
  // drupal_get_form retrieves the privatemsg form
  // $uid is the author of the node
  // $title is the title of the node
  $form = str_replace("\r", '', str_replace("\n", '', drupal_get_form('privatemsg_new', $uid, $title)));

  // javascript that runs jquery_impromptu on flag event
  print '<script language="javascript">';
  print "
  $(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
    if(data.flagStatus == 'flagged'){
      $.prompt('$form');
    }
  });
  ";
  print '</script>';

  // Necessary because previous module_load_include changes title
  drupal_set_title(check_plain($node->title));

For more information on how you can customize the privatemsg form, look here http://drupal.org/node/624528

Help improve this page

Page status: Not set

You can: