Welcome Guest, Not a member yet? Register   Sign In
Can somebody tell me where I'm going wrong with "callback_" ?
#1

[eluser]Jason W[/eluser]
Hi guys.
I'm trying to write a method/function that will validate a users age, but I'm having trouble grabbing the concept of when and how to use "callback_", and I believe that is where my problem is with this function. I'm very new to codeignitor and kinda new to OOP, so go easy on me.
I've pasted the code for my controller below, I hope someone can help. Thanks in advance.


Here's my controller code:
Code:
<?php

class Age extends Controller {
    
    function Age() {

        parent::Controller();        

        $this->load->helper("url");

        $this->load->helper("form");

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

    }
    
    function index() {
        // SET RULES
        $this->form_validation->set_rules('dob_d', 'day of your birth', 'required');
        $this->form_validation->set_rules('dob_m', 'month of your birth', 'required');
        $this->form_validation->set_rules('dob_y', 'year of your birth', 'required');
        $this->form_validation->set_rules('dobcheck', 'dob check', 'callback_age_check');

        
        // FORM ERROR MESSAGES
        $this->form_validation->set_message('required', 'Please enter the %s.');    
        
        // AGE CHECK (for my "callback_" thingy)
        function age_check() {            
            $d = $this->input->post('dob_d');
            $m = $this->input->post('dob_m');
            $y = $this->input->post('dob_y');
            if($d != "" && $m != "" && $y != "") { // If date fields are not empty, then proceed
                // PREP DATE
                $dob = date("M", $m)." ".$d.", ".$y;

                // PROCEED WITH VALIDATION
                $then = strtotime($dob); // Timestamp from DOB
                $min = strtotime('+16 years', $then); // DOB Timestamp + 16 years
                if(time() < $min) {
                    $this->validation->set_message('age_check', 'The %s field can not be the word "test"');
                    return FALSE; // Under 16;
                } else {
                    $this->validation->set_message('age_check', 'The %s field can not be the word "test"');
                    return TRUE; // Over 16;
                }    
            } else {
                return "Date of Birth is incomplete";
            }
        }
        
        // LOAD VIEW
        if ($this->form_validation->run() == FALSE) {
            $this->load->view("signup/register");
        } else {
            $this->load->view("signup/success");
        }
    }    
}
    
?&gt;


Messages In This Thread
Can somebody tell me where I'm going wrong with "callback_" ? - by El Forum - 10-17-2009, 04:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB