title: how to validate array value in codeigniter
body: <p>I have in my form work experience which is added dynamically with input as organisation name, department name, position and duration.</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;&lt;span class="serial_no"&gt;1&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="organization[]" size="50"/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="department[]" size="50"&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="positions[]" size="40"&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="duration[]"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>While validating in CI I did the following:</p>
  
  <pre><code>$organization = $this-&gt;input-&gt;post('organization');
  $department   = $this-&gt;input-&gt;post('department');
  $positions    = $this-&gt;input-&gt;post('positions');
  $duration     = $this-&gt;input-&gt;post('duration');
  
  //printr($organization);
  for($i = 0; $i &lt; count($organization); $i++) 
  {
      $org = $organization[$i];
      $dept = $department[$i];
      $pos = $positions[$i];
      $dura = $duration[$i];
  
      $this-&gt;form_validation-&gt;set_rules($org, "Organization", "trim|xss_clean|max_length[1]");
      $this-&gt;form_validation-&gt;set_rules($dept, "Department", "trim|xss_clean|max_length[50]");
      $this-&gt;form_validation-&gt;set_rules($pos, "Position", "trim|xss_clean|max_length[40]");
      $this-&gt;form_validation-&gt;set_rules($dura, "Duration", "trim|xss_clean|integer");
  }
  </code></pre>
  
  <p>And displayed error as:</p>
  
  <pre><code>&lt;?php
      echo form_error("organization[]");
      echo form_error("department[]"); 
      echo form_error("positions[]"); 
      echo form_error("duration[]");
  ?&gt; 
  </code></pre>
  
  <p>Now the problem is it doesn't validate the duration as integer. Even if I put some random alpha characters it doesn't show errors.</p>
  
  <p>When I validate as follows:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('organization[]', "Organization", "trim|xss_clean|max_length[50]");
  $this-&gt;form_validation-&gt;set_rules('department[]', "Department", "trim|xss_clean|max_length[50]");
  $this-&gt;form_validation-&gt;set_rules('positions[]', "Position", "trim|xss_clean|max_length[40]");
  $this-&gt;form_validation-&gt;set_rules('duration[]',"Duration", "trim|xss_clean|numeric");
  </code></pre>
  
  <p>It doesn't let me submit the form as it takes duration as mandatory which it isn't.</p>
  
  <p>How do I solve it?</p>
  
  <p>any help/suggestions are welcome. thanks.</p>