Reputation: 245
Hello my lovely stackies,
After alot of research and no working solution I thought I would try my luck here. I have a button which POST a formular of a user to the my server. But my huge problem is, when the user clicks the button how much he wants, I get the formular as often as he clicked on it.
My button and send function is:
echo "<form name=\"myForm\" method=\"POST\" action=\"aktenerfassung.php?id=$id&mandnr=$mandnr&countBeleg=$countBeleg\"> \n";
echo "<p align=\"center\"><input id=\"absenden\" align=\"center\" type=\"submit\" value=\"Fehler korrigieren\" name=\"B1\"></p> \n";
echo "</form> \n";
unset($clsAktenerfassung);
My solution would be:
$(function() {
$('absenden').on('click', function(e) {
var trigger = $(this),
clickCount = trigger.data('clickCount');
clickCount++;
trigger.data('clickCount', clickCount);
}
if(clickCount > 1) {
alert('schon einmal klicken')
}
});
But I can still press the button how much I want and still don't get a alert. I dont even get a error message from PHP.
This should be the alert:
if(clickCount > 1) {
alert('schon einmal klicken')
}
If anything is unclear or you need other information or this post already exists in stackoverflow, please tell me.
Thank you already!!
Upvotes: 2
Views: 203
Reputation: 15247
I was facing the same issue, and instead of catching "more than 1 click", I decided to disable the button and change its text with something like "Sending datas..."
. I used this simple code to achieve that, with jQuery :
$('form[name=myForm]').submit(function()
{
$('#absenden').attr("disabled", true);
$('#absenden').html("Sending datas...");
});
The event is fired on the form submission, instead of the submit button, because a user can submit with enter or return key.
Upvotes: 3