Disable submit button after submitting and handling PHP code (Submit with AJAX?)
<p>So I have a form set up for a vote page with submit buttons. It works fine with the form and the php code and everytime someone press the vote button for a specific value it will be count by 1.</p>

<p>Because I am using submit buttons to count the vote, users can spam the buttons because there is nothing what will stop them, for example someone can press the button "wordpress" 10 times so the value of wordpress becomes +10. To prevent that I would like to use a disable button function with Jquery. I've managed to get that function working with a jquery code but unfortunately it will not handle the PHP code from above (through the form).</p>

<p><strong>Question</strong></p>

<p>So my question, How can I disable a submit button after submitting a form and handling the php code of the form?</p>

<p><strong>AJAX</strong></p>

<p>Is it possible to  do it with AJAX? And how? I have 0 knowledge about AJAX  and don't know if this will help my problem. </p>

<pre><code>&lt;?php
        $votestring = 'Klik &lt;a href="/sofeed/uitslagsofeed.php"&gt;hier&lt;/a&gt; om naar de resultaten te gaan';

        if(isset($_POST['wordpress'])) {

            $vote_wordpress = "update stemmen set value1=value1+1";

            $run_wordpress = mysqli_query($dbCon, $vote_wordpress);

            if ($run_wordpress){

                echo 'U heeft uw stem uitgebracht op ' . $answer1 .'!&lt;br&gt;';
                echo $votestring;
            }
        }

        if(isset($_POST['laravel'])) {

            $vote_laravel = "update stemmen set value2=value2+1";

            $run_laravel = mysqli_query($dbCon, $vote_laravel);

            if ($run_laravel){

                echo 'U heeft uw stem uitgebracht op ' . $answer2 .'!&lt;br&gt;';
                echo $votestring;
            }
        }

        if(isset($_POST['html'])) {

            $vote_html = "update stemmen set value3=value3+1";

            $run_html = mysqli_query($dbCon, $vote_html);

            if ($run_html){

                echo 'U heeft uw stem uitgebracht op ' . $answer3 .'!&lt;br&gt;';
                echo $votestring;
            }
        }

        if(isset($_POST['css'])) {

            $vote_css = "update stemmen set value4=value4+1";

            $run_css = mysqli_query($dbCon, $vote_css);

            if ($run_css){

                echo 'U heeft uw stem uitgebracht op ' . $answer4 .'!&lt;br&gt;';
                echo $votestring;
            }
        }

        if(isset($_POST['bootstrap'])) {

            $vote_bootstrap = "update stemmen set value5=value5+1";

            $run_bootstrap = mysqli_query($dbCon, $vote_bootstrap);

            if ($run_bootstrap){

                echo 'U heeft uw stem uitgebracht op ' . $answer5 .'!&lt;br&gt;';
                echo $votestring;
            }
        }
        ?&gt;

    &lt;div class="row"&gt;
        &lt;form name="stemmen" id="formstemmen" action="stemmensofeed.php" method="post"&gt;

        &lt;div class="col-xs-12 col-sm-3 col-md-2 col-lg-1" style="margin-bottom: 10px;"&gt;

            &lt;?php if (!empty($answer1)) { echo '&lt;input type="submit" id="wordpress" class="btn btn-primary" name="wordpress" value='.$answer1.'&gt;'; } ?&gt;

        &lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-3 col-md-2 col-lg-1" style="margin-bottom: 10px;"&gt;

            &lt;?php if (!empty($answer2)) { echo '&lt;input type="submit" class="btn btn-primary" name="laravel" value='.$answer2.'&gt;'; } ?&gt;

        &lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-3 col-md-2 col-lg-1" style="margin-bottom: 10px;"&gt;

            &lt;?php if (!empty($answer3)) { echo '&lt;input type="submit" class="btn btn-primary" name="html" value='.$answer3.'&gt;'; } ?&gt;

        &lt;/div&gt;

        &lt;div class="col-xs-12 col-sm-3 col-md-2 col-lg-1" style="margin-bottom: 10px;"&gt;

            &lt;?php if (!empty($answer4)) { echo '&lt;input type="submit" class="btn btn-primary" name="css" value='.$answer4.'&gt;'; } ?&gt;

         &lt;/div&gt;

        &lt;div class="col-xs-12 col-sm-3 col-md-2 col-lg-1" style="margin-bottom: 10px;"&gt;

            &lt;?php if (!empty($answer5)) { echo '&lt;input type="submit" class="btn btn-primary" name="bootstrap" value='.$answer5.'&gt;'; } ?&gt;

        &lt;/div&gt;

        &lt;/form&gt;



    &lt;/div&gt;

    &lt;!-- jQuery 2.2.0 --&gt;
    &lt;script src="admin/plugins/jQuery/jQuery-2.2.0.min.js"&gt;&lt;/script&gt;
    &lt;!-- Include all compiled plugins (below), or include individual files as needed --&gt;
    &lt;script src="bootstrap-sass/assets/javascripts/bootstrap.js"&gt;&lt;/script&gt;
&lt;script&gt;


    $('input#wordpress').click(function(e) {
        e.preventDefault();
        var aaa =  $(this);
        aaa.prop('disabled', true);
        setTimeout(function() {
            aaa.prop('disabled', false);
        }, 3000);
    });
&lt;/script&gt;
</code></pre>

<p><strong>EDIT</strong></p>

<pre><code> $(function () {

    $('form').on('submit', function (e) {

        e.preventDefault();

        $.ajax({
            type: 'post',
            url: 'stemmensofeed.php',
            data: $('form').serialize(),
            success: function () {
                $('input').prop('disabled', true);
                alert('Your vote is saved!');
            }
        });

    });

});
</code></pre>

<p>So I have pasted in some AJAX code instead of the jquery code. This will work, as the submit buttons will disable after the submit. But, it is still not handling the php code.</p>