Welcome Guest, Not a member yet? Register   Sign In
Callback parameters are not printing correct values.
#1

[eluser]Ninjabear[/eluser]
MY_Controller
Code:
//Check that end date is after start date.
            function _check_start_end_date($start_date,$end_date)
            {
            echo $start_date.' - '.$end_date;
          
                    if( empty($start_date))
                            return true;
          
                    if(strtotime($end_date) > strtotime($start_date))
                    {
                      return true;
                    }
                    $this->form_validation->set_message('_check_start_end_date', 'The start date must be before the end date.');
                    return false;
            }

The output from the echo $start_date.' - '.$end_date; is "2012-12-26 - 2012-12-26" even though the dates coming back from post() are "2012-12-17 - 2012-12-26". Furthermore this function has worked fine in the past and I've called it in this way lots of times. I'm assuming that the param below in brackets is the second param to function right? The first param is the field value in question.

Controller
Code:
$this->form_validation->set_rules("date_work_began","Date work began","trim|required|callback__Valid_Date_Format");
            $this->form_validation->set_rules("date_work_ended","Date work ended","trim|callback__Valid_Date_Format|callback__check_start_end_date[{$this->input->post('date_work_ended')}]" );

So the result from the function is false or "The start date must be before the end date.". But it should be true.
#2

[eluser]CroNiX[/eluser]
Since date_work_ended is a post value, you don't really need to pass it. Just access the post value directly in your callback. I have a feeling it's the way you're writing the passed in parameter, but you don't really need it anyway. Either that or try just passing the field NAME in set_rules() and then accessing the post value of the field NAME in the callback.

Code:
$this->form_validation->set_rules("date_work_ended","Date work ended","trim|callback__Valid_Date_Format|callback__check_start_end_date[date_work_ended]");

Code:
function _check_start_end_date($start_date,$end_date)
{
    $end_date = $this->input->post($end_date);
    //....
#3

[eluser]CroNiX[/eluser]
I also notice you are applying that rule to the 'date_work_ended' field, so you are using 2 fields of the same thing. So I don't think you are comparing the start and end dates. Only the end dates. The first parameter of the callback is the field value that the rule was applied on.
#4

[eluser]Ninjabear[/eluser]
I can't hard code the value because I want to be able to reuse the callback. So I have lots of start and end dates in various websites and I need to be able to use the same callback in all of them.

But you did solve the problem. Why was I passing end date into end date! I should have used the rule on the start date and passed end date in.




Theme © iAndrew 2016 - Forum software by © MyBB