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.

<?php
  // 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

Related posts:


blog comments powered by Disqus