如何从HTML表单中放入一个

我正在尝试将表单放入表单中,这是我的代码:

<form action="info.php" method="post" id="test1">
        <input type="hidden" name="name" value="test">
        <a id="test" style="text-decoration:none;" onclick="document.getElementById('test1').submit();">
            <!-- somestuff -->
            <form action="insertCart.inc.php" method="POST" id="tset11">
                    <p class="card button"><button type="button" onclick="document.getElementById('test11').submit();" name="add-to-cart">Add to Cart</button></p>
                </form>
            </div>
        </a>
    </form>

我已经用onclick尝试了很多JavaScript,但是如果我单击from中的按钮,那么它将提交id为“ test1”的from。 有什么办法可以解决吗?

评论
占领网吧
占领网吧

您不能将表单标签嵌套在另一个表单中。

点赞
评论
hquia
hquia

您不能嵌套表格,这是无效的HTML。

However, what you can do is use the form attribute in your inputs to create the same effect.

From https://stackoverflow.com/a/54901309/1600379:

<form id="main-form" action="/main-action" method="post"></form>
<form id="sub-form"  action="/sub-action"  method="post"></form>

<div class="main-component">
    <input type="text" name="main-property1" form="main-form" />
    <input type="text" name="main-property2" form="main-form" />

    <div class="sub-component">
        <input type="text" name="sub-property1" form="sub-form" />
        <input type="text" name="sub-property2" form="sub-form" />
        <input type="submit" name="sub-save" value="Save" form="sub-form" />
    </div>

    <input type="submit" name="main-save" value="Save" form="main-form" />
</div>
点赞
评论