Welcome Guest, Not a member yet? Register   Sign In
Problems with validation....
#1

[eluser]louis w[/eluser]
I have this code:

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

// ...

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

$rules    = array('sButton' => 'required');
$this->validation->set_rules($rules);
$this->validation->set_fields($itemfields);

if ($this->validation->run() == FALSE)
    echo $this->validation->error_string;


My $itemfields array print_r's as this:

Code:
Array
(
    [sButton] => sfsdfsdafasdfasdf
)

When I run validation I get this error:
The sfsdfsdafasdfasdf field must have a value.

What is going on? Why is it using the value of the field instead of it's name?

Furthermore, I tried setting a custom error message just for this field like this:
$this->validation->set_message('sButton', 'CUSTOM MESSAGE!!!');
And it didn't do anything.
#2

[eluser]louis w[/eluser]
UPDATE:
Just realized I was using $this->validation->set_fields($fields); incorrectly...

But I guess this brings up another question... how do i get the validation to check not just at $_POST but $_POST['itemfields']? I prefer to group my submitted form elements into an array for easier passing around.
#3

[eluser]louis w[/eluser]
Looks like there is no way to override the root _POST.

It would be nice if this change could be incorporated to allow the validation library to be a little more flexible.

Code:
function run($source=$_POST)
    // Then change all references of $_POST to $source




Theme © iAndrew 2016 - Forum software by © MyBB