I want to submit multiple forms with only 1 buttons outside all of the form. This is the 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">
And when i click the button, it will go to the addToCartFood.php and these are the codes
$_SESSION['Date'] = $_POST['Date']; $_SESSION['Name'] = $_POST['Name']; $_SESSION['AdultQ'] = $_POST['Adult']; $_SESSION['KidsQ'] = $_POST['Kids']; $_SESSION['telnum'] = $_POST['telnum']; $_SESSION['comment'] = $_POST['comment'];
Thank you in advance
Advertisement
Answer
why multiple forms ? just merge them all in one form only as action and method is same for all
<form id="allform" class = "NameInput" action="addToCartFood.php" method="POST"> Name: <input type="text" class = "inputName" name="Name" value=""><br> Date: <select name="Date" class = "Date"> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> </select> July 2020 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> <input type="submit" class = "submitbtn" form="allform" value="Add to Cart"> </form>