Welcome Guest, Not a member yet? Register   Sign In
Problem validating start and end dates with call back
#1

[eluser]Wayne Smallman[/eluser]
Hi guys!

I'm trying to validate start and end dates. I have a number of call back functions, most of which work fine, but one in particular stubbornly refused to work:

Code:
private function date_check_compare () {

    if (!$this->ion_auth->logged_in()):

        redirect('users/login/');

    else:

        if (strtotime($this->input->post('start')) >= strtotime($this->input->post('close'))):

            $this->form_validation->set_message('date_check_compare', 'The end date must be greater than the start date.');

            return false;

        else:

            return true;

        endif;

    endif;

}
I've pulled out the conditional part of the code and run that separately, and validates fine, as expected. But for some unknown reason, the call back simply doesn't not work:

Code:
$arraySetRules = array(
   array(
         'field'   => 'start',
         'label'   => 'Start Date',
         'rules'   => 'trim|required|callback_date_check_format|callback_date_check_valid|callback_date_check_years'
      ),
   array(
         'field'   => 'close',
         'label'   => 'End Date',
         'rules'   => 'trim|required|callback_date_check_format|callback_date_check_valid|callback_date_check_compare'
      )
);
As far as I can see, all is fine. But I may be missing something.
#2

[eluser]JonoB[/eluser]
I'm working with callbacks at the moment as well, so I feel your pain. First off, are you 100% sure that your callback function is actually being called?

Code:
private function date_check_compare () {
var_dump('callback is being called');
....
}

On a separate issue, I noticed that you use:
Code:
if (!$this->ion_auth->logged_in()):

        redirect('users/login/');

    else:
Do you have this in every single controller method? If so, there is a MUCH easier way to do this. Have a look at http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
#3

[eluser]Wayne Smallman[/eluser]
Hi Jono, thanks for the reply.

The var_dump() function doesn't do anything at all. I've checked the function name and the name of call back several times.

The user validation would bounce the user back to the sign-in screen, if there was a problem.

Right now, I'm asking about the call back issue, that's all.
#4

[eluser]Wayne Smallman[/eluser]
OK, after several tests, none of the call back functions are working.

At this stage, I need to offer some background — I'm moving code from an application written on CodeIgniter 1.7 to CodeIgniter 2.0, where all of the call backs are working fine with the previous version of the application.
#5

[eluser]Wayne Smallman[/eluser]
Hi guys, do we have any takers on this?

I can't figure this one out — all custom call back functions do not trigger, while the standard call back functions work fine.
#6

[eluser]Ricardo SDL[/eluser]
I'm with problems here too. I updated the codeigniter code to the version 2.0.1 and all my callbacks aren't being called anymore. Ideas anyone?
#7

[eluser]InsiteFX[/eluser]
If your Callbacks are not in the same module as the form_validation do not use private!
Callbacks should be public not private!

InsiteFX
#8

[eluser]Ricardo SDL[/eluser]
My callbacks are public methods inside the same controller that has the validation code.
#9

[eluser]Ricardo SDL[/eluser]
Found the solution here:
http://www.mahbubblog.com/php/form-valid...deigniter/




Theme © iAndrew 2016 - Forum software by © MyBB