[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