Welcome Guest, Not a member yet? Register   Sign In
form_textarea() generation issue
#1

[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 --&gt;
          
&lt;?=form_close();?&gt;

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 Tongue


Messages In This Thread
form_textarea() generation issue - by El Forum - 08-05-2008, 01:57 PM
form_textarea() generation issue - by El Forum - 08-05-2008, 02:11 PM
form_textarea() generation issue - by El Forum - 08-05-2008, 02:43 PM
form_textarea() generation issue - by El Forum - 08-05-2008, 04:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB