Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve text fields as an array in PHP
    text
    copied!<p>I have a form as below which allows users to add more input field through a addmore button . my question is how can i retrieve the array in POST and echo them out . as you can see i have two input fields with name product[] and quantity[] (more fields can be added) . i have to get the value of the field using a a foreach loop and store it in a varibla $message to be used in mail(). i have tried a for each loop for both and my for each loop code as below </p> <pre><code>$product = $_POST['product']; $quantity = $_POST['quantity']; foreach($product as $value) { $message = "&lt;html&gt;&lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;".$value.""; } foreach($quantity as $value) { $message.=" &lt;/td&gt; &lt;td&gt;".$value."&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;"; } </code></pre> <p>My input form </p> <pre><code> &lt;form id="quick_post" method="post"&gt; &lt;table id="input_fields"&gt; &lt;tr&gt; &lt;td&gt;&lt;input class="orderinput" type="text" name="product[]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input class="orderquan" type="text" name="quantity[]" size="1" maxlength="3" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input class="more" type="button" value="Addmore" name="addmore" /&gt; // a jquery script is processed on click to add more fields. &lt;input class="send" type="submit" value="Send" name="send" /&gt;&lt;/form&gt; </code></pre> <p>the output for this is i get only the first row of products printed and for the remaining row only the quantity is printed or echoed. as below </p> <pre><code>Product Name Quantity aaaaaa 22 33 </code></pre>
 

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