[eluser]Nameless One[/eluser]
[quote author="TheFuzzy0ne" date="1238540440"]I use set_value(), which is defined in the form helper, and auto-loaded by the Form Validation library? The second parameter is where you specify the default value; set the defaults from the database.[/quote]
I'm quite sure this results in an if for each field. I prefer having a single if in the controller which determines which set of data to use for the form.
Since I keep the form field names such that all data is submitted associative arrays that are members of $_POST, for example name="data[entry_name]", the best solution I found right now is this:
When the data is fetched from the database, I pass it on to the view and it is used to populated the fields. When the user is returned to the form because of an error, I pass on the variable $entity = (object) array_merge($this->input->post($data),$this->input->post($additional_data)) which results in the object which is the same as the one fetched from the database (except for the primary key which is not used in populating the fields anyway).
I have another problem with Validation class now, which might prevent me from using it at all. It doesn't seem to work with field names that I use: name="data[field]". I set the rules like this:
Code:
$this->validation->set_rules(array(
'data[field1]' => 'required',
'data[field2]' => 'required|alpha_numeric'
));
I also tried like this:
Code:
$this->validation->set_rules(array(
'data' => array(
'field1' => 'required',
'field2' => 'required|alpha_numeric'
)
));
Nothing works.