Welcome Guest, Not a member yet? Register   Sign In
complex form help
#1

[eluser]dadamssg[/eluser]
can you not define a function in a controller and then use it in another function?? im trying validate a script that uses dates and its saying that im calling an undefined end_timestamp(). Im trying to use my function end_timestamp() in my hasnt_ended() function
Code:
function create()
    {
        if($this->session->userdata('logname')){}else
        {
        redirect('mains');
        }
    
    
        $data['notifications'] = $this->Loginmodel->get_notifications();
        $data['messages'] = $this->Loginmodel->get_messages();
        $data['title'] = "Publish Event";
        $this->load->view('header_view', $data);
        #####decide which views to load###################
        if($this->session->userdata('logname') == "")
        {
        $this->load->view('login_view', $data);
        }
        else
        {
        $this->load->view('logged_view', $data);
        }
        $this->load->helper('url');
        $this->load->helper('form');
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('title', 'Title', 'trim|required');
        $this->form_validation->set_rules('location', 'Location', 'trim|required');
        $this->form_validation->set_rules('description', 'Description', 'trim|required');
        $this->form_validation->set_rules('smonth', 'Smonth', 'callback_start_date');
        $this->form_validation->set_rules('emonth', 'Emonth', 'callback_end_date|callback_hasnt_ended');
        
        
        $this->form_validation->set_error_delimiters('<h5>', '</h5>');

                if ($this->form_validation->run() == TRUE)
                {
                $this->load->view('main_view');    
                }
                else
                {
                    
                    $this->load->view('create_event');
                }
        
        $this->load->view('footer_view');
    }
    
    
    function end_date()
    {
        if(checkdate($_POST['emonth'], $_POST['eday'], $_POST['eyear']))
        {
        return TRUE;
        }else
        {
        $this->form_validation->set_message('end_date', "Your end date doesn't exists.");
        return FALSE;
        }
    }
    
    function start_date()
    {
        if(checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear']))
        {
        return TRUE;
        }else
        {
        $this->form_validation->set_message('start_date', "Your start date doesn't exists.");
        return FALSE;
        }
    }
    
    function start_timestamp()
    {
        if($_POST['sampm'] == "pm")
        {
        $sh = $_POST['shour'] + 12;
        $start = mktime($sh,$_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
        return $start;
        }
        else
        {
        $start = mktime($_POST['shour'],$_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
        return $start;
        }
    }
    
    function end_timestamp()
    {
        if($_POST['eampm'] == "pm")
        {
        $sh = $_POST['ehour'] + 12;
        $end = mktime($sh,$_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
        return $end;
        }
        else
        {
        $end = mktime($_POST['ehour'],$_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
        return $end;
        }
    }
    
    function hasnt_ended()
    {
    $hr = (int) date("H")+5;
    $mi = (int)  date("i");
    $mo = (int) date("n");
    $da = (int) date("j");
    $yr = (int) date("Y");
    $now = gmmktime( $hr,$mi,0,$mo,$da,$yr);
    $end = end_timestamp();
    if($end > $now)
        {
        return TRUE;
        }else
        {
        $this->form_validation->set_message('hasnt_ended', "Your event has already ended.");
        return FALSE;
        }
    
    }


Messages In This Thread
complex form help - by El Forum - 01-12-2010, 08:14 PM
complex form help - by El Forum - 01-12-2010, 08:52 PM
complex form help - by El Forum - 01-12-2010, 09:14 PM
complex form help - by El Forum - 01-12-2010, 09:15 PM
complex form help - by El Forum - 01-12-2010, 09:21 PM
complex form help - by El Forum - 01-12-2010, 09:23 PM
complex form help - by El Forum - 01-12-2010, 09:38 PM
complex form help - by El Forum - 01-12-2010, 09:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB