PHP不处理表格 [英] PHP doesn't process the form
问题描述
我在这里有一个小问题.
我有一个带有jQuery的表单,该表单在提交表单时禁用了提交输入.
问题是:单击输入提交时,我使用PHP处理数据.但是显然该按钮首先被禁用,然后PHP无法执行该处理.我需要找到一种方法来防止这种情况,请看一下代码片段:
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函数:
jQuery function to disable:
$('.send').on('submit', function()
{
$(this).find('input[type="submit"]').prop("disabled", true);
});
然后处理PHP代码:
if(isset($_POST['finish']))
{
//Do things
}
正如我所说,PHP不处理表单,因为JS禁用了该按钮以防止多次提交.禁用按钮之前如何处理PHP?谢谢!
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!
推荐答案
由于您禁用了提交按钮,因此它不会被发送到$_POST
变量中的服务器上,因此您的代码无法正常工作说.
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.
要做的另一种方法是创建隐藏的HTML输入
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
}
这篇关于PHP不处理表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!