CodeIgniter form_validation中的无效


<form action="<?php echo base_url().'login/index'; ?>" method="post" name="loginForm" id="loginForm">
<div class="mb-3">
<input type="text" class="form-control" id="username" name="username" autocomplete="off">
</div>
<div class="mb-3">
<input type="password" class="form-control" id="password" name="password" autocomplete="off">  
</div>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>

控制器

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {

public function index()
{
$this->load->library('form_validation');
$this->form_validation- 
>set_rules('username','username','required');
$this->form_validation- 
>set_rules('password','Password','required');

if($this->form_validation->run() == false){
$this->load->view('admin/login');
}
else{
echo"Form validation Successfully";
}


}
}

您在使用base_url()时没有添加此库

// need this to use base_url() in the template.php
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

再试一次

相关内容

  • 没有找到相关文章