title: How to hide a field when editing that is visible when adding an item?
body: <p>I have a problem with trying to hide a field when editing an entry that must be visible when adding an entry.</p>
  
  <p>My table structure is as follows:</p>
  
  <pre><code>equip_items
  --------------
  id (pk)
  equip_type_id (fk to equip_types)
  site_id (fk to sites)
  equip_status_id (fk to equip_status)
  name
  </code></pre>
  
  <p>(equip_type_id, site_id, name) is a composite unique key constraint in the db. I have implemented a callback on the name field that deals with grocery_CRUD validation of the unique constraint - taking into account either editing existing or adding new equip_items.</p>
  
  <pre><code>function unique_equip_item_check($str, $edited_equip_item_id){
  $var = $this-&gt;Equip_Item_model-&gt;is_unique_except($edited_equip_item_id,$this-&gt;input-&gt;post('site_id'),$this-&gt;input-&gt;post('equip_type_id'),$this-&gt;input-&gt;post('name'));
  
  if ($var == FALSE) {
  $s = 'You already have an equipment item of this type with this name.';
  $this-&gt;form_validation-&gt;set_message('unique_equip_item_check', $s);
  return FALSE;
  } else {
  return TRUE;
  }
  }
  </code></pre>
  
  <p>I have the site_id and equip_type_id set as hidden fields as I do not want the user to change these - no problem.</p>
  
  <pre><code>$crud-&gt;field_type('site_id', 'hidden', $site_id);
  $crud-&gt;field_type('equip_status_id', 'hidden', iQS_EqStatus_InUse);
  </code></pre>
  
  <p>When users add an equip_item I want them to be able to select the equip_type from a list of types - No problem, this is default grocery_CRUD behaviour.</p>
  
  <pre><code>$crud-&gt;add_fields('equip_status_id', 'site_id', 'equip_type_id', 'name');
  </code></pre>
  
  <p>When users edit an equip_item I don't want the user to be able to edit the equip_type. I figured no problem I can just set the edit_fields to exclude equip_type_id:</p>
  
  <pre><code>$crud-&gt;edit_fields('equip_status_id', 'site_id', 'name', 'barcode_no');
  </code></pre>
  
  <p>BUT this plays havoc with my validation callback because the value of the equip_type_id field is nowhere on the edit form and it is obviously needed by my validation routine.</p>
  
  <p>So I need to have the equip_type_id field visible and acting normal when adding a new record but hidden when editing a record.</p>
  
  <p>I've tried this hack of all hacks :</p>
  
  <pre><code>if ($this-&gt;uri-&gt;segment(4)!= FALSE){$crud-&gt;field_type('equip_type_id', 'hidden');}
  </code></pre>
  
  <p>My theory was that "$this->uri->segment(4)" only give a false result if adding a new record, but it does not work.</p>
  
  <p>I have also tried:</p>
  
  <pre><code>$crud-&gt;callback_edit_field('equip_type_id', array($this,'edit_equip_type_field_callback'));
  </code></pre>
  
  <p>with</p>
  
  <pre><code>function edit_equip_type_field_callback($value = '', $primary_key = null){
  return '&lt;input type="hidden" value="'.$value.'" name="equip_type_id"';
  }
  </code></pre>
  
  <p>But that doesn't work it just screws up the layout of the form fields - the 'Type' label etc is still visible.</p>
  
  <p>Any suggestions?</p>