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