在另一个表格中提交表格 [英] submit a form inside another form

查看:118
本文介绍了在另一个表格中提交表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有POST方法的表单和另一个页面的操作。

I have a form with POST method and an action of another page.

在表单中,我有另一个表单,我需要使用不同的操作提交但是它以主表格行动提交。

Within the form i have another form that I need to make submit with a different action but its submitting with the main form action.

这是我的第二种形式:

<script>
    function formSubmit()
    {
        document.getElementById("invoices_form").submit();
    }
</script>

<form action="resend_multiple_invoices.php" name="invoices_form" method="post">
    <input type="button" onclick="formSubmit()" value="Send Invoices" />
</form>

如何才能提交第二张表格而非主要表格?

how can i get it to submit the second form and not the main one?

推荐答案

您不能(普遍)提交与其父表单分开的嵌套表单。嵌套表单是无效的HTML,如 W3C禁令中所述。

You cannot (universally) submit a nested form separately from its parent form. Nested forms are invalid HTML as outlined in the W3C prohibitions.

为了解决您的问题,我建议您使用以下两种不同的表格:

To solve your problem, I suggest you use two separate forms as follows:

<script>
    function invoicesFormSubmit()
    {
       document.getElementById("invoices_form").submit();
    }

    function otherFormSubmit()
    {
       document.getElementById("other_form").submit();
    }
</script>

<form action="resend_multiple_invoices.php" name="invoices_form" method="post">

    //
    // Input fields go here
    //

    <input type="button" onclick="invoicesFormSubmit()" value="Send Invoices" />
</form>

<form action="other_method.php" name="other_form" method="post">

    //
    // Input fields go here
    //

    <input type="button" onclick="otherFormSubmit()" value="Other Method" />
</form>

这篇关于在另一个表格中提交表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆