Pedro Posada | Avoid duplicating posts

Avoid duplicating posts

Posted on April 9, 2008 - 4:51pm
<< 42 of 50 >>

This code is very useful to avoid duplicated posts in your Drupal site. Some times when users try to submit a form, the form will take more than usual to reload or to respond. In those cases you want to have the submit button to disappear and to show a message saying that the form is being processed. I found this piece of code somewhere in the durpal.org site. I have been using it all the time and works like a charm.

This is a jQuery snippet and goes inside a block or page or node.

<?php
function hide_buttons(){
   
$data = '
    var touched;
    var t;
   
    function disabler(){
        touched.attr("disabled","disabled");
        clearTimeout(t);
    }
   
    $(document).ready(function() {
           $("input[@type=submit]").mouseup(function() {
              $(this).siblings("input[@type=submit]").hide();
              touched = $(this);         
              t = setTimeout("disabler()", 10);
              $(this).after("<span>Loading...</span>");
            });      
          });'
;
   
   
// don't allow users to post content more than once
   
drupal_add_js( $data, 'inline');
}
?>

then you can call the function anywhere you want like:

<?php

hide_buttons
()

?>

It will affect all the submit buttons on the page.

Post new comment

The content of this field is kept private and will not be shown publicly.
Please solve the math question. This way we will know you are not a robot.