2018-10-05 06:36 浏览 63


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\"> 
echo "<p align=\"center\"><input id=\"absenden\" align=\"center\" type=\"submit\" value=\"Fehler korrigieren\" name=\"B1\"></p> 
echo "</form> 

My solution would be:

$(function() {

    $('absenden').on('click', function(e) {
        var trigger = $(this),
        clickCount = trigger.data('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!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    donglian1953 donglian1953 2018-10-05 06:41

    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 :

        $('#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.

    点赞 评论 复制链接分享