codeigniter custom form validation call back url is not working

2k Views Asked by At

hi i am using codeigniter form validation , i want to add a custom form validation for my price field

i am trying this

in controller

$this->ci->form_validation->set_rules ( 'price', 'Price', 'callback_test' ); 

and i have function

private function test()
{
    echo "hello"; die ;
}

i am trying to add a custom call back url test here . but is not working

i am trying this example

http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks

but i do like this the validation works

$this->ci->form_validation->set_rules ( 'price', 'Price', 'required' );

why is my call back url function does not working . please help me . thanks..............

1

There are 1 best solutions below

0
On

You custom callback function needs to return either TRUE or FALSE to work correctly. Also, putting a die() statement doesn't really help you here...

This is a trivial code example but I hope you get the picture:

$this->form_validation->set_rules ( 'price', 'Price', 'required|callback_test' );

function test($string)
{
   return ($string == 'something') ? TRUE : FALSE;
}

$string is the value coming from the input->post and is automatically passed to your callback function. You also need to specify an error message to this callback, otherwise you'll get an error of "no error message provided for custom field", or something like that.

$this->form_validation->set_message('test', 'The value you provided is not in the right format');