Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comments
Where did you put the code?
Where did you put the code?
I agree? Useful stuff, but no
I agree? Useful stuff, but no idea how to implement it?
Where to put it
I added it to the content-type's node template page.
I downloaded and activated
I downloaded and activated Impromptu Module, downloaded the .js file, renamed it an uploaded the file to the right directory. In flag module I choose form submit, put the code in the content-type but it doesn't seem to work. No messages send. What I did wrong? Its a really nice feature, - should be implement in flag...