Welcome Guest, Not a member yet? Register   Sign In
Native PHP Functions Are Not Applied When Using Form Validation set_data();
#1

[eluser]bogdan3l[/eluser]
Code:
$this->load->library('form_validation');

$this->form_validation->set_rules('name', 'Name', 'trim|strtolower|required');

if ($this->form_validation->run())
{
    // trim & strtolower was applied
    echo $this->input->post('name');
}

How can I get the same result as the above but with set_data() as shown below?

Code:
$data = array('name' => 'John Doe');

$this->load->library('form_validation');

$this->form_validation->set_data($data);

$this->form_validation->set_rules('name', 'Name', 'trim|strtolower|required');

if ($this->form_validation->run())
{
    // trim & strtolower was not applied
    echo $data['name'];
}

Any help is appreciated! Thank you!
#2

[eluser]Ckirk[/eluser]
This is a codeigniter 3.0 function and it's still in development.
Not sure how to use this one. Have you referred to the dev documents? http://cryode.github.io/CodeIgniter/

Kepp in mind that it's not even a release so there might be buggy code all over the place
#3

[eluser]bogdan3l[/eluser]
I know and yes, I've checked the http://cryode.github.io/CodeIgniter/ but without any luck.

Thanks!
#4

[eluser]slowgary[/eluser]
I realize this post is somewhat old, but just an FYI for anyone that lands here looking for the same thing (like myself)...

CodeIgniter 3.0's Form_validation library adds a new feature that allows one to arbitrarily set the data that should be validated, instead of using $_POST.

The feature functions somewhat, but at a quick glance it appears the library still attempts to set the values to the post array after validation. This means you can still use the library to set your own data array, but the library will arbitrarily populate the $_POST array with your data afterwards (hopefully not overwriting $_POST data that you're also collecting) and in addition, you'll not be able to reap the benefits of chaining any sanitization methods within your validation rules (trim, strtolower, etc).




Theme © iAndrew 2016 - Forum software by © MyBB