title: How to display form field on condition using PHP in CodeIgniter?
body: <p>I have select input in my form for manufacturers. </p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label for="manufacturer"&gt;Manufacturer&lt;/label&gt;
      &lt;select id="manufacturerSelect" name="manufacturer" class="form-control"&gt;
          &lt;option disabled selected value&gt; -- select an manufacturer -- &lt;/option&gt;
          &lt;?php foreach ($manufacturers as $manufacturers_item): ?&gt;
              &lt;option value="&lt;?=$manufacturers_item['id'];?&gt;" &lt;?php echo set_select('manufacturer',$manufacturers_item['id'], ( !empty($manufacturer) &amp;&amp; $manufacturer == $manufacturers_item['id'] ? TRUE : FALSE )); ?&gt; &gt;&lt;?=$manufacturers_item['name'];?&gt;&lt;/option&gt;
          &lt;?php endforeach; ?&gt;
           &lt;option disabled&gt;──────────&lt;/option&gt;
          &lt;option value="24" &lt;?php echo set_select('manufacturer','24', ( !empty($manufacturer) &amp;&amp; $manufacturer == '24' ? TRUE : FALSE )); ?&gt; &gt;Other&lt;/option&gt;
      &lt;/select&gt;
      &lt;?php echo form_error('manufacturer'); ?&gt;&lt;br /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If "other" (value == 24) is checked additional input is asked:</p>
  
  <pre><code>$('body').on('change', '#manufacturerSelect', function() { 
      if ($(this).val() == 24) {
          $("#otherManufacturerSelect").removeClass('hidden');
      } else {
          $("#otherManufacturerSelect").addClass('hidden')
      }
  });
  </code></pre>
  
  <p>And HTML:</p>
  
  <pre><code>&lt;div id="otherManufacturerSelect"  class="form-group"&gt;
      &lt;label for="otherManufacturer" &gt;What is it then?&lt;/label&gt;
      &lt;input type="text" name="otherManufacturer" class="form-control"&gt;
      &lt;?php echo form_error('otherManufacturer'); ?&gt;&lt;br /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>.hidden {
      display: hidden;
  }
  </code></pre>
  
  <p>Now if user picks "other" as manufacturer addition input is displayed. Form validation rule for otherManufacturer is added in server side if <code>manufacturer == 24</code>. The problem is that the other manufacturer input is displayed every time user get response from server. I could add <code>class="hidden"</code> by default to other manufacturer div but if the form validation doesnt run other manufacturer field will not be displayed again to user.</p>
  
  <p>What I need is PHP IF condition inside:</p>
  
  <p><code>&lt;div id="otherManufacturerSelect" &lt;?php if(/*???*/):?&gt;class="hidden"&lt;?php endif; ?&gt; class="form-group"&gt;</code> </p>
  
  <p>So that <code>class="hidden"</code> would be added only if manufacturer is not "other". but I cannt think of rigth condition. </p>
  
  <p>Any help would be appreciated!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Controller:</p>
  
  <pre><code>public function create()
  {
      $this-&gt;load-&gt;helper(array('form', 'url'));
      $this-&gt;load-&gt;library('form_validation');
  
      $this-&gt;form_validation-&gt;set_rules('manufacturer', 'Manufacturer', 'required');
      if($this-&gt;input-&gt;post('manufacturer') == '24'){
          $this-&gt;form_validation-&gt;set_rules('otherManufacturer', 'Other manufacturer', 'required');
      }
  
      $data['manufacturers'] = $this-&gt;puzzles_model-&gt;getManufacturers();
  
      if ($this-&gt;form_validation-&gt;run() === FALSE)
      {
          $this-&gt;load-&gt;view('puzzles/create', $data);
      }
      else
      {
          /* do the upload, return upload errors or save in db*/
      }
  }
  </code></pre>