title: Should I use set_value() to repopulate a form in CodeIgniter
body: <p>My question is whether I should use set_value() at all to re-populate a form.  It might seem odd to say that, however I am creating a shared controller function and view which can be used to either add a new record or edit an existing one.  It seems to make sense to do this since the functionality is so incredibly alike.</p>
  
  <p>As such, if we call up an existing record to edit I do this:</p>
  
  <pre><code>$data['fields'] = $this-&gt;customer_model-&gt;get_customer($id);
  </code></pre>
  
  <p>If the form is submitted to save the record, or if we're adding a record for the first time, the form has the potential to reload if the user makes a mistake so I populate $data['fields'] this way instead:</p>
  
  <pre><code>$data['fields'] = array(
      'company' =&gt; $this-&gt;input-&gt;post('company') ?: '',
      'website' =&gt; $this-&gt;input-&gt;post('website') ?: '',
      'credit_limit' =&gt; $this-&gt;input-&gt;post('credit_limit') ?: ''
  );
  </code></pre>
  
  <p>My form element looks like this:</p>
  
  <pre><code>&lt;input type="text" name="company" value="&lt;?php echo set_value('company', $fields['company']); ?&gt;"  /&gt;
  </code></pre>
  
  <p>But I'm thinking it may as well look like this:</p>
  
  <pre><code>&lt;input type="text" name="company" value="&lt;?php echo escape_html($fields['company']); ?&gt;"  /&gt;
  </code></pre>
  
  <p>Since the form data could come from either user input (when adding or saving) or from the database (when retrieving a record to edit) I cannot rely entirely on <code>post()</code> or <code>set_value()</code> without the 2nd parameter.  Furthermore, the second parameter for set_value() will always exist (<code>$fields['company']</code> in this example) because it's initialized from the start, which is why I am thinking of just using it directly.</p>
  
  <p>Is there a problem with this approach?</p>