CodeIgniter Forums
Best way for getting form values - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Best way for getting form values (/showthread.php?tid=54982)



Best way for getting form values - El Forum - 10-04-2012

[eluser]ojcarga[/eluser]
Guys,

Just wondering if you can explain me the difference between these two way for getting values on form submission:

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

&&

Code:
$this->input->post('login')

Both works perfectly but dont know which is the difference.

Thanks,
Cheers!


Best way for getting form values - El Forum - 10-04-2012

[eluser]LuckyFella73[/eluser]
"set_value" is used when repopulating form values
in case the form_validation failed. You echo it
in the "value" attribute of your form field.

To get the submitted form data and process it in
your controller use
Code:
$my_value = $this->input->post('name_form_field');



Best way for getting form values - El Forum - 10-04-2012

[eluser]ojcarga[/eluser]
Thanks,

yeah, that's the way I do it but checking the Tank_auth code I just realized that it does it (catch values in the controller after form submission) using the first one method:
Code:
$this->form_validation->set_value('login')

I'm just asking cause really don't know if doing it that way gain/lose something, i don't know.

Cheers!


Best way for getting form values - El Forum - 10-04-2012

[eluser]LuckyFella73[/eluser]
Code:
$this->form_validation->set_value('login')

Afaik this line is just to SET the value. If you look
at the code in tank auth it's not processed furthermore.
I don't know why he had this at all because if you run
the form_validation all values of the fields defined in
the rules are set automatically.