Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest you use '[]', as it groups multiple input fields to an array.</p> <pre><code>&lt;?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS); $to = "test@mywebsite.com"; $subject = "New Order"; $order = array(); $order['name'] = $_POST['name']; $order['phone'] = $_POST['phone']; $food = $_POST['food']; foreach ($food as $type =&gt; $value) if (strlen($value['quantity']) &gt; 0) // assuming 'customize' is optional $order[$type] = $value; print_r($order); } ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Order now!&lt;/title&gt; &lt;style&gt;label,input,textarea {display:block}&lt;/style&gt; &lt;body&gt; &lt;?php // You need enctype for '[]' support' ?&gt; &lt;form action="" method="post" enctype="multipart/form-data"&gt; &lt;div class ="item"&gt; &lt;label&gt;Mexican Torta - $8.50&lt;/label&gt; &lt;b&gt;How Many?&lt;/b&gt; &lt;input name="food[mexican_torta][quantity]" type="text"&gt; &lt;b&gt;Customize It? &lt;font color="#999999"&gt;Ex: No Lettuce, Extra Cheese...&lt;/font&gt;&lt;/b&gt; &lt;textarea name="food[mexican_torta][customize]"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class ="item"&gt; &lt;label&gt;Fish - $3.50&lt;/label&gt; &lt;b&gt;How Many?&lt;/b&gt; &lt;input name="food[fish][quantity]" type="text"&gt; &lt;b&gt;Customize It? &lt;font color="#999999"&gt;Ex: No Lettuce, Extra Cheese...&lt;/font&gt;&lt;/b&gt; &lt;textarea name="food[fish][customize]"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;h2&gt;Place Your Order Now:&lt;/h2&gt; &lt;em&gt;Fill in the form below, and we'll call you when your food is ready to be picked up.&lt;/em&gt; &lt;label&gt;Enter your name&lt;/label&gt; &lt;input type="text" name="name"&gt; &lt;label&gt;Enter your phone nr.&lt;/label&gt; &lt;input type="text" name="phone"&gt; &lt;button&gt;Submit&lt;/button&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <hr> <p>User submits (for example I left the fish blank) and you get </p> <pre><code>Array ( [name] =&gt; Fab [phone] =&gt; 1212 [mexican_torta] =&gt; Array ( [quantity] =&gt; 2 [customize] =&gt; Test ) ) </code></pre> <p>Play around a bit with the '[]' to get the array output you really desire. The print_r will show you exactly what you get. From here it is really easy to put the food details in the e-mail</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload