title: CodeIgniter form validation optional based on value
body: <p>I'm setting up a form with CI and I'm using the form validation to help me with this.</p>
  
  <p>At the moment I have different rules setup, like</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('first_name', 'First Name', 'required|xss_clean');
  </code></pre>
  
  <p>But in my form I have a checkbox, enabling the checkbox will show some new inputs that are required when the checkbox is checked.
  When the checkbox is unchecked these fields are not required.</p>
  
  <p>What would be the best method to do this in CI?</p>
  
  <pre><code>// Set validation rules
  $this-&gt;form_validation-&gt;set_rules('first_name', 'First Name', 'required|xss_clean');
  $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'required|xss_clean');
  // Some more rules here
  
  if($this-&gt;form_validation-&gt;run() == true) {
      // Form was validated
  }
  </code></pre>