Welcome Guest, Not a member yet? Register   Sign In
Form Validation Library - Properly Retrieving Data
#1

[eluser]oliverkalen[/eluser]
I apologize for my ignorance here.

What is the proper way to retrieve validated data for inserting into a database, etc?

Code:
$email = $this->form_validation->_field_data['email']['postdata'];

Code:
$email = $this->input->post('email');

Has the data returned by the post() function been run through the appropriate validation rules?

i.e. if one of my rules is "trim" will the post() function returned a trimmed value or the original data with trailing spaces?

Or is there another method I am missing?
#2

[eluser]Thorpe Obazee[/eluser]
I don't know about the first one but I believe that

Code:
$this->input->post('email');

has already been passed to the appropriate validation rules

The same with

Code:
set_value('email');
#3

[eluser]Michael Wales[/eluser]
The validation library will repopulate all of the variables with the new value, after the validation rules have been put into effect, so all of these are the same:

Code:
$_POST['email'];
$this->input->post('email');
$this->form_validation->email;
$this->form_validation->_field_data['email']['postdata'];

Personally, I prefer using the Input class, just to improve the readability in my Controller. I would definitely avoid the $_POST array and the _field_data method (that is prepended by an underscore, meaning it should be considered a private method).
#4

[eluser]Thorpe Obazee[/eluser]
Wow. I never knew about that last one Michael. I will stick to the input class which I always use. I believe it's just a matter of preference, no?
#5

[eluser]oliverkalen[/eluser]
Michael,

Thank you for the detailed response. I will sick to using the Input Class since that seems to be the cleanest approach.

This might be good information to add to the User Guide under the Form Validation documentation ... unless I just missed it.

The new Form Validation Library is a great improvement over the previous version.
#6

[eluser]mindesign[/eluser]
This would be really good to add to the form validation documentation as I wasn't really sure how to do it at all and only could find the answer here. THANKS!




Theme © iAndrew 2016 - Forum software by © MyBB