populate form from database |
[eluser]deltrem[/eluser]
In the controller, I have... function update($id = null) { $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->load->database(); $data = array(); $data = $this->db->get_where( 'users', array( 'id' => $id ) ); $data = $data->result_array(); $data = $data[0]; $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|matches[emailconf]'); $this->form_validation->set_rules('emailconf', 'Email Confirmation', 'required'); $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); $this->form_validation->run(); this->load->vars($data); $this->load->view('update'); } In the view, I have... <h5>Username</h5> <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" /> <h5>Email</h5> <input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" /> <h5>Email Confirmation</h5> <input type="text" name="emailconf" value="<?php echo set_value('emailconf'); ?>" size="50" /> <h5>Password</h5> <input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" /> <h5>Password Confirmation</h5> <input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" /> I have seen set_value() reading $data at http://ellislab.com/forums/viewthread/103837/ What am I doing wrong?
[eluser]Dam1an[/eluser]
I'm not too sure about the structure of your code there, the normal logic using the form_validation class is Code: // Massivly simplified login controller The view is pretty much the same as yours Also, whya re you passing the data array to the view, you never seem to use it? Or am I missing something Oh, and can you please use [ code ] blocks next time
[eluser]Thorpe Obazee[/eluser]
Code: <input type=“text” name=“username” value=”<?php echo set_value(‘username’, content_from_db); ?>” size=“50” /> You need the second parameter of the set_value helper.
|
Welcome Guest, Not a member yet? Register Sign In |