The validation of the form does not work in the codeigniter

advertisements

I am working with codeigniter. I have created one function to add university form.

function add_uni_admin()
{
    $user_id = $this->session->userdata("user_id");
    if (!empty($user_id)) {
            $uni_name = $this->input->post("uni_name");
            $uni_image = $this->input->post("uni_image");
            $uni_email = $this->input->post("uni_email");
            $phn_no = $this->input->post("phn_no");
            $m_no = $this->input->post("m_no");
            $address = $this->input->post("address");
            $password = $this->input->post("pass");

            $this->form_validation->set_rules('uni_name', 'University Name', 'required');
            $this->form_validation->set_rules('uni_email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('phn_no', 'Phone Number', 'required');
            $this->form_validation->set_rules('m_no', 'Mobile Number', 'required');
            $this->form_validation->set_rules('address', 'Address', 'required');
            $this->form_validation->set_rules('pass', 'Password', 'required|matches[conf_pass]');
            $this->form_validation->set_rules('conf_pass', 'Confirm Password', 'required');

            if ($this->form_validation->run() == false) {
                $this->load->view("admin/add_uni_admin");
            } else {
                echo "successfull";exit;
            }
    } else {
        redirect(base_url());
    }
}

When I submit the form without filling any field then it does not give any error.Here I have added form_validation library into autoload.php file and added form helper in it.

So what code should I have to write to display errors?


use echo validation_errors() in your view to display errors.

<html>
<head>
  <title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

**your form here.**

</body>
</html>