Welcome Guest, Not a member yet? Register   Sign In
[solved]Form validation rules "lesser_than" not working
#8

[eluser]brucebat[/eluser]
Code:
class Submit extends CI_Controller
    {
    
            public function displayform()
            {
                //prevents guest users accessing or users not logged in
                if ( $this->session->userdata('name') == FALSE)
                {
                redirect ('site/index');// to home page
                }
            
            
            $page['page'] = 'submit';
            $this->load->view('template', $page );
        
            }
    
    
            public function validateform()
            
            {
                $this->load->library('form_validation'); //loads form validation library from CI
                
                
                /*for ($i =0; $i< 30; $i++)
                {
                    $this->form_validation->set_rules('time'.$i, 'Time'.$i, 'xss_clean|required');
                    $this->form_validation->set_rules('event'.$i, 'Event'.$i, 'xss_clean|required');
                    $this->form_validation->set_rules('supplies'.$i, 'Supplies'.$i, 'xss_clean');
                    $this->form_validation->set_rules('success'.$i, 'Success'.$i, '');
                    $this->form_validation->set_rules('comment'.$i, 'Comment'.$i, 'xss_clean');
                } */
            
                $this->form_validation->set_rules ('patient_age','Patient Age','numeric|trim|required|less_than[110]|xss_clean'); //if patient is older than 110 years return false
                $this->form_validation->set_rules ('patient_gender', 'Gender', 'required');
                $this->form_validation->set_rules ('patient_weight', 'Patient Weight', 'trim|numeric|required|less_than[200]|xss_clean'); //if patient is heavier than 200kg return false
                $this->form_validation->set_rules ('patient_height', 'Patient Height', 'trim|numeric|required|less_than[220]|xss_clean');  //if patient is taller than 220 cm return false
                
                
                
                
                if ($this->form_validation->run() == FALSE)
                {
                    echo "Failed validation";
                    $this->displayform();
                }
                
                else
                
                {
                    $this->load->model('submit_model');
                    $this->submit_model->create_record();
                    if ($this == FALSE)
                    {
                        echo "Failed to add to database";
                    }
                    
                    else
                    {
                        echo "Successfully added";
                    }
                }
            }

Basically what happens is when I call the function in the same controller called "Submit" I get my validation errors but the text boxes lose their values.

Once again thankyour for your kind help Smile


Messages In This Thread
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 04:34 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 04:38 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 04:42 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 06:45 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 06:52 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 06:57 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 07:01 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 07:06 AM
[solved]Form validation rules "lesser_than" not working - by El Forum - 07-01-2011, 07:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB