PHP 用 1 个按钮提交多个表单

我想提交多个表单,所有表单外只有 1 个按钮。这是 index.php


 <form id="allform" class = "NameInput" action="addToCartFood.php" method="POST">

            Name:   <input type="text" class = "inputName" name="Name" value=""><br>

 </form>


 <form id="allform" action="addToCartFood.php"  method="POST">

            Date:       

            <select name="Date" class = "Date">

                <option value="26">26</option>

                <option value="27">27</option>

                <option value="28">28</option>

            </select>

            July 2020

</form>

<form id="allform" action="addToCartFood.php" method="POST">

            Adult:      

            <select id = "selectboxAdult" name="Adult" class = "Adult" onchange = "calculateAll(<?php echo $_SESSION['price'];?>)">

                <option value="1">1</option>

                <option value="2">2</option>

                <option value="3">3</option>

                <option value="4">4</option>

            </select>

</form>


<input  type="submit" class = "submitbtn" form="allform" value="Add to Cart">

当我单击按钮时,它将转到 addToCartFood.php,这些是代码


$_SESSION['Date'] = $_POST['Date'];

$_SESSION['Name'] = $_POST['Name'];

$_SESSION['AdultQ'] = $_POST['Adult'];

$_SESSION['KidsQ'] = $_POST['Kids'];

$_SESSION['telnum'] = $_POST['telnum'];

$_SESSION['comment'] = $_POST['comment'];


芜湖不芜
浏览 144回答 1
1回答

PIPIONE

为什么有多种形式?只需将它们全部合并为一种形式,因为动作和方法对所有人都是相同的<form id="allform" class = "NameInput" action="addToCartFood.php" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name:&nbsp; &nbsp;<input type="text" class = "inputName" name="Name" value=""><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Date:&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select name="Date" class = "Date">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="26">26</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="27">27</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="28">28</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; July 2020&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Adult:&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select id = "selectboxAdult" name="Adult" class = "Adult" onchange = "calculateAll(<?php echo $_SESSION['price'];?>)">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="1">1</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="2">2</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="3">3</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="4">4</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select><input&nbsp; type="submit" class = "submitbtn" form="allform" value="Add to Cart"></form>
打开App,查看更多内容
随时随地看视频慕课网APP