简体   繁体   中英

PHP doesn't process the form

I'm having a little problem here.
I have a form with a jQuery that disables the submit input when the form is submited.
The problem is: I use PHP to process the data when the input submit is clicked. But apparently the button is being disabled first, then PHP can not perform the processing. I need to find a way to prevent this, take a look in the code snippets:

<form class='send' action='{$_SERVER['PHP_SELF']}' method='post'>
    <!--Form data-->
    <input type='submit' name='finish' value='Send'/>
</form>

jQuery function to disable:

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

And then the PHP code to process:

if(isset($_POST['finish']))
{
    //Do things
}

As I said, the PHP don't process the form because JS disabled the button to prevent multiple submitions. How to process PHP before disable the button? Thanks!

Since you are disabling the submit button it will not get send over to to server in the $_POST variable so your code doesn't work, as you have said.

Another way to do what you are looking for is to create a hidden HTML input

<input type="hidden" name="form">

Then when you check if the form is send, you will use

if(isset($_POST['form']))
{
    //Do things
}

You can solve it easily changing your submit button by a simple button:

<form class='send' action='{$_SERVER['PHP_SELF']}' method='post'>
    <!--Form data-->
    <input type='button' name='finish' value='Send'/>
</form>

$('input[name="finish"]', '.send').on('click', function(){
    $(this).prop('disabled', true);
    $('.send').submit();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM