Welcome Guest, Not a member yet? Register   Sign In
$this->form_validation->run() is altering $_POST
#1

Hello,

I don't understand what happens with the following code:

Code:
var_dump( $this->input->post('username') );
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->run();
var_dump( $this->input->post('username') );

First var_dump() output:
Code:
string(1) ">"

Second var_dump() output:
Code:
string(4) ">"

In my actual code, this issue prevents me from doing this:
Code:
// In the controller:
$value = form_prep( $this->input->post('username') );

// In the view :
<input type="text" name="username" value="<? echo $value ?>">

It is very easy to fix in the above example, but my actual code is much more complicated, and the only easy fix I have found is this:

Code:
$post_backup = $_POST;
$this->form_validation->run();
$_POST = $post_backup;

Is it a bug in Codeigniter that $_POST is altered by $this->form_validation->run() ? The documentation says nothing about this behavior.
Reply
#2

Actually it my be something wrong with your .htaccess. As far as I see from the library's code, Codeigniter form_validation doesn't mess with the $_POST. Try this: http://stackoverflow.com/questions/47331...n-htaccess
Reply
#3

Perhaps you are calling a one of the Form Validation prepping functions (such as prep_for_form)?

From the User Guide:

In addition to the validation functions like the ones we used above, you can also prep your data in various ways.

Note: You will generally want to use the prepping functions after the validation rules so if there is an error, the original data will be shown in the form.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB