Note that there are some explanatory texts on larger screens.

plurals
  1. POappended elements not picked up in POST data
    primarykey
    data
    text
    <p>I have an order page with the following fields:</p> <pre><code>quantity, id, name, language, publisher </code></pre> <p>There are initially 10 fields created on my php page, with this code:</p> <pre><code>&lt;form action="new_order.php" method="POST"&gt; &lt;fieldset&gt; &lt;div id="inputRows"&gt; &lt;div class="controls controls-row"&gt; &lt;label class="span1"&gt;Qty&lt;/label&gt; &lt;label class="span1"&gt;ID&lt;/label&gt; &lt;label class="span5"&gt;Literature&lt;/label&gt; &lt;label class="span2"&gt;Language&lt;/label&gt; &lt;label class="span2"&gt;Publisher&lt;/label&gt; &lt;/div&gt; &lt;?php $i = 0; //make 10 initial order forms for($i; $i &lt;10; $i++) { echo "&lt;div class=\"controls controls-row\"&gt;\r\n"; echo "&lt;input class=\"span1\" type=\"text\" id=\"quantity\" name=\"order[{$i}][quantity]\"&gt;\r\n"; echo "&lt;input class=\"span1\" type=\"text\" id=\"id\" name=\"order[{$i}][id]\"&gt;\r\n"; echo "&lt;input class=\"span5\" type=\"text\" id=\"name\" name=\"order[{$i}][name]\"&gt;\r\n"; echo "&lt;select class=\"span2\" type=\"text\" id=\"language\" name=\"order[{$i}][language]\"&gt;\r\n"; foreach($lang as $k=&gt;$v) { echo "&lt;option value=\"{$k}\"&gt;" . $v . "&lt;/option&gt;\r\n"; } echo "&lt;/select&gt;\r\n"; echo "&lt;input class=\"span2\" type=\"text\" id=\"publisher\" name=\"order[{$i}][publisher]\"&gt;\r\n"; echo "&lt;/div&gt;\r\n"; echo "\r\n"; } ?&gt; &lt;/div&gt; &lt;input type="button" id="addline" value="Add Another Line" &gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;hr /&gt; &lt;button type="submit" name="submit" class="btn btn-primary" value="order"&gt;Add Order&lt;/button&gt; &lt;button type="submit" name="submit" class="btn" value="cancel"&gt;Cancel&lt;/button&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>All well and good. The form loads fine. All the options are fine. I checked the source code.</p> <p>Now, I have a bit of jQuery at the top, which lets me add another field. I had it setup to insert a whole row with these same fields, but to make it simple, let's just do one text field:</p> <pre><code>$(function() { $('#addline').on('click', function() { nInput = '&lt;input type="text" name"text1" &gt;'; $('#inputRows').append(nInput); }); }); </code></pre> <p>It adds the row just fine. No problem. When I submit the page to itself, the original 10 arrays get picked up just fine, but the new field is not passing through.</p> <p>I was researching Stack and other sites, and something I read somewhere said that this happens because the form has already loaded, and so when you add another input field, it isn't included as part of the form data. Is this what's happening? If so, is there another way to do it?</p> <p>Does this have to do with the fact that I'm using the .on() function versus the .click() function? Or because it's running at $('document').ready()? After everything has indeed loaded?</p> <p>EDIT: Here is the php script that it submits to:</p> <pre><code>&lt;?php require_once("../../includes/initialize.php"); if(!isset($_SESSION['user_id'])) { redirect("login.php"); } if(isset($_POST['submit']) &amp;&amp; $_POST['submit' == 'order']) { include("html/neworder.html.php"); } </code></pre> <p>And here is the print_r($_POST), which is called from the included neworder.html.php file:</p> <pre><code>Array ( [order] =&gt; Array ( [0] =&gt; Array ( [quantity] =&gt; [id] =&gt; [name] =&gt; [language] =&gt; en [publisher] =&gt; ) [1] =&gt; Array ( [quantity] =&gt; [id] =&gt; [name] =&gt; [language] =&gt; en [publisher] =&gt; ) //etc... [9] =&gt; Array ( [quantity] =&gt; [id] =&gt; [name] =&gt; [language] =&gt; en [publisher] =&gt; ) ) [submit] =&gt; order ) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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