0

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

4
  • 1
    Why do you have multiple forms Commented Mar 23, 2020 at 10:26
  • Aside: Is there a real need to transfer raw values to session variables? Or use sessions at all? Personally I try and keep session data to a minimum - token like data. Commented Mar 23, 2020 at 10:37
  • I used multiple forms so i could do css easily (?) but i think thats not a good idea based on the answers lol. For the session, i want to print all the values to the cart page. Is there any easier way? Commented Mar 23, 2020 at 10:45
  • 1
    you'd better use <div> instead of form to wrap fields, and then apply CSS for wrapping div Commented Mar 23, 2020 at 11:12

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.