title: Passing dynamically created form fields to PHP
body: <p>I am trying to pass dynamically created form fields to a php script, and it's causing me a huge headache.</p>
  
  <p>I've done this in the past many times, and I can't figure out what i'm doing wrong here.</p>
  
  <p>Below is an example of what's going on:</p>
  
  <p>A brief explanation: I have a form with a textarea, there is a button named "Add More", when clicked, a new textarea is generated via javascript. The textareas values are pushed into an array named "comments". When I try to loop through this array within my php script, it only gives me the first item, and none of the dynamically created ones.</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;form action="" method="post" enctype="multipart/form-data" accept-charset="utf-8"&gt;
  &lt;textarea name="comments[]"&gt;&lt;/textarea&gt;
  &lt;a href="javascript: return null;" class="add-more"&gt;Add More&lt;/a&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$(".add-more").click(function(){ 
  
         var new_field = '&lt;textarea name="comments[]"&gt;&lt;/textarea&gt;';
         $(this).before(new_field);
  
  }); 
  </code></pre>
  
  <p>PHP - this is where the issue is, when I try to loop through the comments[] array, it only gives me the first one, and does not bring through any of the ones that were generated dynamically.</p>
  
  <pre><code>&lt;?php
  
  $comments = $_POST['comments'];
  
  $commentString = "";
  foreach($comments as $value) {
  $commentString .= $value;
  }
  
  ?&gt;
  </code></pre>
  
  <p>So with the above, if I create 5 textareas using the "Add More" button, input some text into each one, and then submit the form, none of the dynamically created fields send through to the php.</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks!!</p>