• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
callback feature on form validation library

#1
[eluser]Unknown[/eluser]
Hi,
The 'callback' feature on the form validation library does not seem to work.

I have tried everything but the below won't work. Can someone please help? Sad



Code:
class Myform extends MY_Controller {

    function Myform()
    {
        parent::MY_Controller();
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
    }

    function index() {    
        $this->form_validation->set_rules('datecreated', 'datecreated', 'callback_date_check');
        $this->form_validation->set_error_delimiters('<li>', '</li>');

        if ($this->form_validation->run() == FALSE) {
            $this->display('upload/index', $data);
        }

    }

    function date_check($str) {        
        echo "functionm called";
        exit;
    }

#2
[eluser]Sarfaraz Soomro[/eluser]
try just the field name and the callback as the argument, don't know why you put the second argument as 'datecreated'

Code:
$this->form_validation->set_rules('datecreated','callback_date_check');

alternately you can try this syntax;

Code:
$this->form_validation->set_rules( array( 'datecreated' => 'callback_date_check' ) );

#3
[eluser]Sarfaraz Soomro[/eluser]
also it's a good practice to prefix the validation callbacks with an underscore.

Code:
$this->form_validation->set_rules( array( 'datecreated' => 'callback__date_check' ) );

and you define your callback function as;

Code:
function _date_check($str)

#4
[eluser]Sarfaraz Soomro[/eluser]
oh i am sorry i failed to recognize earlier that you are using the new Form Validation library. I made the comment above because i am more used to the old validation class in 1.6.3 version.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.