Welcome Guest, Not a member yet? Register   Sign In
How to re-populate the form with values from the database?
#4

[eluser]cahva[/eluser]
set_value() will take second parameter which you can use to populate the fields if data has not yet been sent. With that you can set the default value if the value is not posted yet. Something like this..

Controller:
Code:
function index()
    {
        $this->load->model('users');
        $this->load->helper('form');
        
        // Get userinfo from model and set it to $data['userinfo']
        $data['userinfo'] = $this->users->get_userinfo();
        
        $this->load->view('user',$data);
    }

View:
Code:
<?php echo form_open('user') ?>
*Username: &lt;input type="text" name="username" value="&lt;?php echo set_value('username',$userinfo-&gt;username) ?&gt;" /><br />
*Email: &lt;input type="text" name="email" value="&lt;?php echo set_value('email',$userinfo-&gt;email) ?&gt;" />
&lt;?php echo form_close() ?&gt;


Messages In This Thread
How to re-populate the form with values from the database? - by El Forum - 07-24-2010, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB