Welcome Guest, Not a member yet? Register   Sign In
Prefill forms from DB array
#1

[eluser]opel[/eluser]
Please could anyone tell me if it is possible or how to prefill a form view with data from my model and controller ?

What I have at the moment is :

Model :

Code:
function get($table, $id)
    {
        $query = $this->db->query("SELECT * FROM $table WHERE $id");
        $result =  $query->row();
    
        var_dump($result);
    
    }

Controller :

Code:
function edit($id){
        
        $data['pagetitle'] = 'Edit';
        
        //Select data based on ID
        $data['body'] = $this->Pages_model->Get('pages', $id);
        
        //write out data
        $this->template->write_view('content', 'pages/page_add', $data);
        
        //render
        $this->template->render();
        
    }

View :

Code:
<h1>&lt;?= $pagetitle; ?&gt;</h1>

&lt;?php

  $id = $this->uri->segment(3);

if($id == NULL){
  $id = 'X';
}




$form = array('name'=>'text','rows' => '10', 'cols' => '30');

$attributes = array('class' => 'email', 'id' => 'myform');

echo form_open('pages/form', $attributes); ?&gt;


&lt;?php echo $this->validation->error_string; ?&gt;

<table>
    <tr>
         <td><label><div align="right">Title : </div></label></td>
        <td>&lt;?= form_input('title'); ?&gt;</p></td>
    </tr>
    <tr>
             <td><label>Message : </label></td>
            <td colspan="2">&lt;?= form_textarea($form); ?&gt;</p></td>
    </tr>
    <tr>
             <td><label><div align="right">Order : </div></label></td>
            <td>&lt;?= form_input('order'); ?&gt;</p></td>
    </tr>
    <tr>
            <td>&nbsp;</td>
            <td>&lt;?= form_submit('submit', 'Add Page') ?&gt;</td>
    </tr>
    <tr>
            <td>&nbsp;</td>
            <td>&lt;?= form_hidden('id', $id) ?&gt;</td>
    </tr>
</table>
&lt;? echo form_close(); ?&gt;


Messages In This Thread
Prefill forms from DB array - by El Forum - 09-28-2008, 04:10 PM
Prefill forms from DB array - by El Forum - 09-28-2008, 07:34 PM
Prefill forms from DB array - by El Forum - 09-29-2008, 02:32 AM
Prefill forms from DB array - by El Forum - 09-30-2008, 07:18 AM
Prefill forms from DB array - by El Forum - 09-30-2008, 09:12 AM
Prefill forms from DB array - by El Forum - 09-30-2008, 03:12 PM
Prefill forms from DB array - by El Forum - 10-01-2008, 02:25 AM
Prefill forms from DB array - by El Forum - 10-01-2008, 04:12 AM
Prefill forms from DB array - by El Forum - 10-01-2008, 04:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB