CodeIgniter Forums
Validation form with fields filled - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Validation form with fields filled (/showthread.php?tid=37515)



Validation form with fields filled - El Forum - 01-12-2011

[eluser]indapublic[/eluser]
There is form with update user profile.

Code:
<div>Username: &lt;?=$this->validation->username_error;?&gt;&lt;input type="text" name="username" value="&lt;?=$this-&gt;validation->username;?&gt;" /></div>

How can I fill fields before the form show?

Code
Code:
$user = $this->user_model->get_user_data($user_id);
$this->validation->username = $user->username;
$rules["username"] = "trim|required|xss_clean";
$this->validation->set_rules($rules);
$fields["username"] = "username";
$this->validation->set_fields($fields);
$this->load->view("users/edit", $user);
is not working.


Validation form with fields filled - El Forum - 01-12-2011

[eluser]mdvaldosta[/eluser]
Validation will only have values once the form is submitted. You'd need to send the pre-populated form variables to the view from your controller first. Then, do an if statement to use the validation values if they exist, else use the database values. Or, something like that.


Validation form with fields filled - El Forum - 01-12-2011

[eluser]indapublic[/eluser]
Ok, i understand. Thanks a lot