1

I can't figure out the problem whats wrong. Form validation error are showing in controller when var_dump in controller but cannot see in view.

Controller

  function submitform() {

    $pid = 16;
    $data['query'] = $this->viewmodel->get_page($pid);
    $data['notices'] = $this->viewmodel->get_notices();
    $data['events'] = $this->viewmodel->get_events();
    $data['gadgets'] = $this->viewmodel->get_gadgets();

    $this->load->library(array('form_validation', 'session'));
    $this->form_validation->set_rules('fname', 'Full Name', 'required|xss_clean|max_length[100]');
    $this->form_validation->set_rules('p_address', 'Permanet Address', 'required|xss_clean|max_length[200]');
    $this->form_validation->set_rules('captcha', 'Captcha', 'callback_validate_captcha');

    if (($this->form_validation->run() == FALSE)) {
        var_dump(validation_errors());     //Validation error is show here but not in view.
        die;
        $this->load->view('header');
        $this->load->view('register', $data);
        $this->load->view('eventsfull', $data);
        $this->load->view('sitemapcontent', $data);
        $this->load->view('footer', $data);
    } else {

        $name = $this->input->post('fname');

        $p_address = $this->input->post('p_address');

        $this->viewmodel->add_alumni($fname, $p_address);
        $this->session->set_flashdata('message', 'Your request has been submited for verify.');
        $data['error'] = "Your data submitted sucessfully.";
    }
    redirect('sres/register');
}

view (register.php)

 <?php echo validation_errors(); ?>

 //FORM element
1
  • redirect('sres/register'); remove the line or keep it inside else condition you will see it works. Commented Jul 5, 2015 at 10:20

1 Answer 1

3

Form validation library will work only when your view loaded as $this->load->view(). In redirection it will not work. You may use session flash data to pass errors in redirection view.

$this->session->set_flashdata('errors', validation_errors());

now view file

 <?php var_dump($this->session->flashdata('errors')); ?>
Sign up to request clarification or add additional context in comments.

2 Comments

This is not the answer I meant. I cannot get validation error even when I loaded view. Can there be any problem.
Where is your register.php file?? In sres directory or views directory? double check you putting validation_errors() in right file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.