[eluser]fdog[/eluser]
I'm using CI form helper to generate the form's inputs. I reuse the same form for inserting and updating. The only difference between the two of them is that the edit-form has the values from the database on the text_inputs (for easy editing).
controller.php:
Code:
/*
$values is a database row
*/
function _get_form($values = null)
{
/* form attribute array */
$form = array(
'tab_form_attributes' => array(
'id' => 'Form',
'method' => 'post'
),
/* I use this array to generate the inputs */
'tab_form_list' => array(
form_label('Name:', 'supplier-name')
.form_input(
array(
'name' => 'supplier-name',
'id' => 'supplier-name',
'size' => '30',
'value' => ( ( $values != null ) ? $values->name : '' ) )), /* prints the value from the database when editing */
form_label('Address:', 'supplier-address')
.form_textarea(
array(
'name' => 'supplier-address',
'id' => 'supplier-address',
'rows' => '90',
'cols' => '12',
'class' => 'description')),
/* Can't use the value attribute in textareas :( */
),
);
return $form;
}
In the View.php, I do:
Code:
<?=form_open('suppliers/update_supplier/'.$supplier_id, $tab_form['tab_form_attributes']);?>
<!-- generate inputs -->
<?=ol($tab_form['tab_form_list'], array('class' => 'forms'));?>
<!-- end generate inputs -->
<--! I create the submit button in a similar way -->
<?=form_close();?>
My problem is: since textareas don't use the value attribute how could I change my code to add text from the database to the textarea?
Note: I really like using the form_helper and the ol() function to create forms