How to disable a submit button after submission in PHP?

how to enable and disable submit button in php
how to disable submit button after form submission in javascript
how to disable button in php
disable submit button onclick
how to disable submit button after form submission in jsp
mvc disable submit button after click
disable submit button php
html disable button until input

I browsed through the other questions on this issue but couldn't find a satisfactory answer. I have a quiz website where the user selects an option from four options and then clicks submit. I want to disable the submit button after it has been clicked once.

Is there any way to do this with PHP? If not, is there a way to do this with minimal JS.

Available Solutions

Since you tagged the question jQuery, here are some simple jQuery solutions you can use: To disable it when it is clicked, you can simply:

$('input[type="submit"]').click(function() {
    this.disabled = true;
};

You can do even better though, and disable it only once the form is submitted:

$("form").submit(function() {
    $(this).find('input[type="submit"]').prop("disabled", true);
});
Solution Demo

Here's a simple demo of the above logic, in a jsFiddle: http://jsfiddle.net/zb8CZ/ (Note that in that implementation I didn't use jQuery, but rather, plain JS; for portability across browsers however, as well as access to the many other methods jQuery provides (plus the syntactic sugar!) I recommend the jQuery methods.

Good to note...

Note that attempting to implement JS event handling inline in your HTML (using the onsubmit="..." or onclick="..." attributes) is considered bad practice, since it muddles your functionality with your layout/display layer. You also lose any syntax highlighting and/or error-checking your editor might provide, as well as just generally making it harder to develop and maintain your application, since there is no logical order to your code.

How to disable a submit button after submission in PHP?, we can prevent double click submit button in jquery html. it will help you to disable submit button after click in php, laravel, codeigniter etc project  Sometime, we have to prevent too many clicks on submit button. if you are working on register form with php then it might be take time to submit form because of long processes of submit page. But if user have server issue or Internet issue etc then he will just click again and again.

I leave a code:

    <form name="myform" action="/" method="post" onsubmit="document.getElementById('submit_button').disabled = 1;">

<!-- form elements here -->

</form>

How to Disable Submit Button After Form Submission in PHP?, I will help you for how to disable submit button after click in jquery php. we can prevent double click submit button in jquery html. it will help you  How to Disable Submit Button After Form Submission in PHP? I will help you for how to disable submit button after click in jquery php. we can prevent double click submit button in jquery html. it will help you to disable submit button after click in php, laravel, codeigniter etc project that use jquery.

For disable write like this, after once click it will be disable.

<input type="submit" id="but_sub" name="submit" \>


    $("#but_sub").click(function() {
        $(this).attr("disabled",true);
    }

or

    $('#but_sub').click(function() {
        $(this).attr("disabled","disabled");
    }

Disable submit button after click - JavaScript, Is it possible to disable the submit button after being clicked once? <form name​="testform" method="post" action="process_form.php" disables the submit button and lets the browser carry on with the form submission. if the  When I add onclick="this.disabled=true;" to the submit button tag, it disables the button upon clicking but does not actually submit the form. Also, I can't have it disable the button if there are required fields missed, as they are sent back to the same page with the fields hightlighted and they wouldn't be able to hit submit a second time to

Try this. You might want to pass the value of each answer to a PHP file that performs backend work via AJAX.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script>
    $('#question').submit(function(){
       //Get the value of the answer that was checked
       var answer = $('input:radio[name=question_one]:checked').val();

       //Use jQuery's AJAX function to send the data to a PHP file that does backend work 
       $.ajax({  
          type:'POST',  
          url:'quiz_backend.php',  
          data:'answer='+ answer,
          success: function() {
              //Hide the submit button upon successful submission
              $('#submit').attr("disabled", true);
              event.preventDefault();
          }
       });
    });
</script>

<form id="question">
   <input type="radio" name="question_one" value="answer_one">A<br />
   <input type="radio" name="question_one" value="answer_two">B<br />
   <input type="radio" name="question_one" value="answer_three">C<br />
   <input type="radio" name="question_one" value="answer_four">D<br />

   <input type="submit" value="submit" id="submit"/>
</form>

More info about jQuery's AJAX call here.

How do you disable a submit button after it's , we can prevent double click submit button in jquery html. it will help you to disable submit button after click in php, laravel, codeigniter etc project that use jquery. If all these validations are passed then only the submit button will be enabled for the visitor to submit. DEMO of disabling submit button with form validation → Inside the window.onload function ( see below for the code ) we have assigned all the form elements to variables and trigger the function validateField by using onchange event handler.

very easy javascript only method

<form action="" method="post" >
<input type="submit" name="SUBMIT" value="Submit Form"
   onclick="this.disabled='disabled';this.form.submit();" />
</form>

Preventing Double Form Submission < JavaScript, How do you disable a submit button after it's clicked once (to prevent onClick="​this.value='Processing form';this.disabled=true;if(Submitting()){this <form action​='someFile.php' method='post' onsubmit='return checkForm()'> This article will show you how to disable the Submit button after it has been click and change the text label to Submitting, please wait Make a backup copy of your existing index.php file. Open file index.php in a plain text editor, such as Notepad.

Disable Form Button on Submit, So when the form is submitted - either by clicking on the submit button or pressing Enter in a text input field - the submit button will be disabled  Okay, so I have just had an idea but I have no idea how to execute. I have a submit button on my form that has a patch() function as I am patching a person/group to a Sharepoint List which Submit() won't do. My idea is, is to have the "Save" button disabled until the required fields are filled i

how to disable a button after click in php, As Sergey mentions, you can't do it 'directly' from php. But you can output the appropriate javascript that will do so. I don't construct pages in  As its stands the submit button gets disabled when pressed. However once pressed it does not seem perform the submit. If I removed the jquery to disable the button, the button then performs the submit normally. How can I disable the button only after it has performed the submit? the current jquery above seems to conflict with the submit operation.

Comments
  • jsfiddle.net/geniuscarrier/vTHm5
  • the solutions seems to be working in the fiddle demo... I am, however a naive in jQuery or Javascript and do not know where to insert the Javascript in my code.... Please help..
  • Please can anyone answer this?
  • And should I place this in <head> ?
  • Given the nature of the question I think it's safe to assume that "submission in PHP" suggests a nice retro 1990's style form processing script whereby the back-end code does what it needs to in-line and also includes the same form in the output - which would make this solution pretty much useless as it stands. The form still needs to submit and unless you specify otherwise the resultant output/page will have no knowledge of this...
  • Yes, the 'valuable' solution stand useless. Any suggestions from your side @Emissary ?
  • The submit button was bot disabled 'if(isset['myvariable']))' after ' $myVariable = isset($_POST['myVariable']) ? $_POST['myVariable'] : '';' If I do not use 'if isset($_POST['ans']))' the PHP code was left of no use.
  • @user2801699 I'm not sure what you are getting at - you'll have to post the relevant parts of your code so we can see where you are going wrong.
  • I solved my concern by placing a div over the submit button after it is pressed once to prevent the user from pressiong it again. I know it is hackish, but I needed to get my site up Soon. Thanks for your help!