CodeIgniter Forums
Form Validation class/repopulating - 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: Form Validation class/repopulating (/showthread.php?tid=24157)



Form Validation class/repopulating - El Forum - 11-01-2009

[eluser]mcair[/eluser]
Noob to CI, need help understand the Form Validation class, specifically when re-populating the form

Controller has logic:
Code:
$this->form_validation->set_rules('shortdesc','League Name','required|trim|min_length[1]|max_length[45]');
    $this->form_validation->set_rules('longdesc','Comments','trim|max_length[255]');

and this appears to work. Having done this, and following the example from the user guide I expect that

Code:
echo 'set_value::shortdesc='.set_value('shortdesc');

will display the submitted value in the shortdesc input field. It doesn't. When I echo the $_POST['shortdesc'] I can see the submitted value. I get the impression from the user guide that set_rules will create and store a member variable on the Form Validation class that corresponds to the input field.

I added the following immediately after the set_rules, it made no difference:

Code:
$fields['shortdesc'] = 'League Name';
    $this->validation->set_fields($fields);


Any guidance you can offer is much appreciated.


Form Validation class/repopulating - El Forum - 11-01-2009

[eluser]Ben Edmunds[/eluser]
Call set_value like so

Code:
$this->form_validation->set_value('shortdesc')

and I'm not sure if you have to but I've always called it after

Code:
$this->form_validation->run()



Form Validation class/repopulating - El Forum - 11-01-2009

[eluser]mcair[/eluser]
Adding the run() does the trick. Cheers!


Form Validation class/repopulating - El Forum - 11-01-2009

[eluser]Ben Edmunds[/eluser]
enjoy!