I am using codeigniter
if ($this->form_validation->run() ) always returns false.
please help me out with this
Here is my controller and view page as shown bellow

This is controller admin.php


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {


    public function index()
    {
        $this->login();
    }

    public function login()
    {
        //echo 'This is admin controller login function';
        $this->load->view('admin/admin_login');
    }

    public function login_validation()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');


        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|sha1');

        $email = $this->input->post('email');
        $password = $this->input->post('password');
        print $password . $email;

        if ($this->form_validation->run() == TRUE)
        {
            //redirect('admin/profile');
            $this->load->view('success');
        }
        else
        {
            $this->load->view('errorrr');


        }

    }
}




admin_login.php is the view

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <title>Admin Login</title>
      <link rel="stylesheet" media="screen" href="<?=site_url('assets/css/bootstrap.min.css');?>" />
   </head>
   <body>
      <div class="container">
         <div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
            <div class="panel panel-info" >
               <div class="panel-heading">
                  <div class="panel-title">Admin Login</div>
                  <div style="float:right; font-size: 80%; position: relative; top:-10px">
                  <a href="#" onClick="$('#loginbox').hide(); $('#forgotbox').show()">Forgot password?</a></div>

               </div>
               <div style="padding-top:30px" class="panel-body" >
                  <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>

                  <?php
                     $form_attributes = array(
                        'class' => 'form-horizontal', 
                        'id' => 'loginform',
                        'role' => 'form'
                        );
                     echo form_open('admin/login_validation', $form_attributes);
                     echo validation_errors();
                  ?>
                     <div style="margin-bottom: 25px" class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                       <?php 
                        $email_attributes = array(
                        'id'=>'login-username',
                        'class' => 'form-control',
                        'name'=>'email',
                        'placeholder' => 'Email',
                        'value'=>set_value('email'),
                        'required'=>'required',
                        'placeholder'=>'UserName',
                        );

                        echo form_input($email_attributes);
                       ?>                                     
                     </div>
                     <div style="margin-bottom: 25px" class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                     <?php 
                        $password_attributes = array(
                        'id'=>'login-password',
                        'class' => 'form-control',
                        'name'=>'password',
                        'placeholder' => 'password',
                        'value'=>set_value('password'),
                        'required'=>'required',
                        'placeholder'=>'Password',
                        );

                        echo form_password($password_attributes);  
                     ?> 
                     </div>
                     <div class="input-group">
                        <div class="checkbox">
                           <label>
                           <?php
                              $checkbox_attributes = array(
                               'name'        => 'remember',
                               'id'          => 'login-remember',
                               'value'       => '1',
                               'checked'     => TRUE,
                              );
                              echo form_checkbox($checkbox_attributes);
                           ?>
                             Remember me
                           </label>
                        </div>
                     </div>
                     <div style="margin-top:10px" class="form-group">
                        <!-- Button -->
                        <div class="col-sm-12 controls">

                      <?php
                              $submit_attributes = array(
                               'name'        => 'submit',
                               'id'          => 'btn-login',
                               'class'       => 'btn btn-success',
                               'value'       => 'Login',
                              );
                             echo form_submit($submit_attributes);
                     ?>

                        </div>
                     </div>

                   <?php
                  echo form_close();
                  ?>
               </div>
            </div>
         </div>

      <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
      <script type="text/javascript" src="<?php echo base_url();?>assets/js/bootstrap.min.js" ></script>
   </body>
</html>

ok i got the error
in admin.php i changed
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');

to
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

but why can't i use xss_clean for email id validation?

we have to load security helper
$this->load->helper('security');

then only we can use xss_clean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.