Welcome Guest, Not a member yet? Register   Sign In
Quick question regarding form_validation
#1

[eluser]batterj2[/eluser]
After you've validated the input (i.e. run() returns true) how do the get the values of the input after they've been trimmed|xss_cleaned|etc.?

I've been getting the values from $_POST but I keep getting a niggling feeling that this is wrong.
#2

[eluser]TheFuzzy0ne[/eluser]
You are correct, however you may be better off accessing the post array like this:

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

CodeIgniter has been designed so that you controller methods should never need to access the $_POST array directly. It's also easier to use. You can do:

Code:
$some_field = $this->input->post('some_field');
{
    # Do something

instead of having to do:
Code:
$some_field = (isset($_POST['some_field')) ? $_POST['some_field') : FALSE;
{
    # Do something

Trust your instincts, the force is strong with you...

Just my 2 pence.
#3

[eluser]batterj2[/eluser]
Does this mean that all the validation actions alter the $_POST values? Say for example someone enters 'text ' and I add a trim tag to the validation rule, does the value of $_POST['field'] change from 'text ' to 'text'?
#4

[eluser]TheFuzzy0ne[/eluser]
Not "all" of the validation actions alter the $_POST array, just some, such as trim, xss_clean, prep_for_form, prep_url, strip_image_tags, encode_php_tags and so on.

I think the rule of thumb is that if the function your using for validation returns anything other than TRUE or FALSE, then the corresponding $_POST field will be set to the return value of that function.
#5

[eluser]CroNiX[/eluser]
Why wouldn't you just use $fieldname = $this->validation->set_value('fieldname'); ?
I believe this is the safe/cleaned variable.
#6

[eluser]pistolPete[/eluser]
[quote author="CroNiX" date="1239398061"]Why wouldn't you just use $fieldname = $this->validation->set_value('fieldname'); ?[/quote]

This method does not work anymore if you use the new Form Validation Class: user_guide/libraries/form_validation.html
#7

[eluser]CroNiX[/eluser]
Strange, Im using it with 1.7.1?
#8

[eluser]pistolPete[/eluser]
The old validation class is still there, but it is deprecated:

Quote:As of CodeIgniter 1.7.0, this Form Validation class supercedes the old Validation class, which is now deprecated. We have left the old class in the library so applications currently using it will not break, but you are encouraged to migrate to this new version.
#9

[eluser]CroNiX[/eluser]
Yes, but the method I mentioned is in the current validation class. Its how you repopulate field data and is in their examples, so, why wouldn't it work? The method is not marked as deprecated.
#10

[eluser]TheFuzzy0ne[/eluser]
I think that's what Pete meant. The whole "$this->validation->whatever()" is deprecated, not the method.




Theme © iAndrew 2016 - Forum software by © MyBB