Easier way to populate form data and validation data in Code Igniter?
- by John
I'm new to code igniter. I'm following the form validation tutorial found at:
http://www.codeignitor.com/user_guide/libraries/validation.html
I find I am typing too much in the view to get the form to re-populate. For example, here's what one of my INPUT fields look like:
<input type="text" name="email" value="<?=$this->validation->email ? $this->validation->email : $array_db_values['email'] ?>" />
Basically, when the form first loads, it should show a value from the database. If the user alters the value and it fails validation, then the form should post the erroneously submitted value.
Does code igniter have a "cleaner" way of rendering this kind of output? Otherwise, I'm going to do something like this in my controller:
$array_db_values = getdbresults();
if($_POST['submit'])
foreach($_POST as $key=>$val)
$array_db_values[$key] = $val;
That way, if postback data exists, it will always override database values.
Then input fields in my view can simply be:
<input type="text" name="email" value="<?=$array_db_values['email'] ?>" />
Is there a better/native CI way to handle this scenario?