title: Processing multiple input fields with codeigniter?
body: <p>The problem I am having is that my ecommerce script allows people to add products to their store. However, those products can have variants... like Color and those variants can have options, like Black, White, and Blue for example. The problem I am having is how exactly do I determine how many options they have entered. Eventually I will have a javascript function add a new input field if they click "add option" but for now I just made 3 input fields like so:</p>
  
  <pre><code>Variant Title:&lt;input type="text" name="variant_title"&gt;&lt;br&gt;
  Variant Option: &lt;input type="text" name="variant_option_1"&gt;&lt;br&gt;
  Variant Option: &lt;input type="text" name="variant_option_2"&gt;&lt;br&gt;
  Variant Option: &lt;input type="text" name="variant_option_3"&gt;&lt;br&gt;
  </code></pre>
  
  <p>Now what I don't know how to do is loop through all the variant_options and if they are not empty add them to a database. I don't want to hard code it in with the names because I don't know how many options they will choose per variant.</p>
  
  <p>I tried doing this:</p>
  
  <pre><code>$i = 1;
              while($this-&gt;input-&gt;post('variant_option_$i') != '')
              {
                  $variant_options[] = $this-&gt;post-&gt;input('variant_option_$i');
                  $i++;
              }
  </code></pre>
  
  <p>But that does not seem to work, as the variant title gets added to the database, however the options do not.</p>
  
  <p>The only thing I need a solution to is to how to actually grab those fields all at once. I was thinking a foreach loop but im not sure.</p>
  
  <p>Thank you.</p>