PHP使用1个按钮和1个操作提交多个表单

PHP使用1个按钮和1个操作提交多个表单,php,Php,我想提交一个按钮和一个行动目标使用PHP多个表单。有可能吗 HTML PHP(test_post.PHP) 我尝试过使用该代码,但它只显示了$\u POST['class']值。对于名称,它显示错误:未定义索引:名称位于… 请给出建议。您不需要每次输入一张表格,您可以在一张表格中获得一百万,因此 <form name="myform" action="test_post.php" method="post"> Name: <input type='text' name='nam

我想提交一个按钮和一个行动目标使用PHP多个表单。有可能吗

HTML

PHP(test_post.PHP)

我尝试过使用该代码,但它只显示了
$\u POST['class']
值。对于名称,它显示错误:
未定义索引:名称位于…


请给出建议。

您不需要每次输入一张表格,您可以在一张表格中获得一百万,因此

<form name="myform" action="test_post.php" method="post">
Name: <input type='text' name='name' />

Class: <input type='text' name='class' />
</form>

<a href="javascript: submitform()">Search</a>

姓名:
类别:
应该没问题,而且你不需要提交js。更好地支持html提交输入

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

实际上,您希望在一个表单上有两个字段,然后可以毫无问题地提交:

<form name="myform" action="test_post.php" method="post">
Name: <input type='text' name='name' />
Class: <input type='text' name='class' />
<input type='submit'>
</form>

姓名:
类别:

或者,如果你在JS代码中做了其他事情,你也可以使用一些JS提交它。

如果jquery是一个选项,那么。延迟可能就是你想要的

function submitform(){
//define a variable where we will store deferred objects
var def = true;

$("form").each(function() {

    var postResult = $.Deferred();

    //.when takes a deferred object as a param. 
    // if we don't pass a deferred object .when treats it as resolved.
    // as our initial value of def=true, the first .when starts immediately
    $.when(def).then(function(){
        $.post('post_destination.php', form.serialize()).done(function(){
            //the chain will fail after the first failed post request
            //if you want all the requests to complete in any case change the above .done to .always
            post.resolve();
        });
    });

    // now we reassign def with the deferred object for the next post request
    def = postResult;
});
}

这是我不久前问这个问题时的链接

为什么不能将这两个输入都放在一个表单中?是的,您似乎在向相同的.php文件提交数据,因为我有一个带有jQuery upload的表单,我想获取upload的值。如果我有一个带有upload函数的表单和一个带有submit the data的表单,会怎么样?提交数据时,我必须获得上传值Too的值。您可以在一个表单中上载和无限多个其他输入。要继续回答@Dagon,表单可以有所有类型的输入(文件、文本、数字、日期、范围等)。您的表单将把每一个都发布到您的php文件中。
<input id="submit" type="submit" value="submit">
<form name="myform" action="test_post.php" method="post">
Name: <input type='text' name='name' />
Class: <input type='text' name='class' />
<input type='submit'>
</form>
function submitform(){
//define a variable where we will store deferred objects
var def = true;

$("form").each(function() {

    var postResult = $.Deferred();

    //.when takes a deferred object as a param. 
    // if we don't pass a deferred object .when treats it as resolved.
    // as our initial value of def=true, the first .when starts immediately
    $.when(def).then(function(){
        $.post('post_destination.php', form.serialize()).done(function(){
            //the chain will fail after the first failed post request
            //if you want all the requests to complete in any case change the above .done to .always
            post.resolve();
        });
    });

    // now we reassign def with the deferred object for the next post request
    def = postResult;
});
}