不应出现第一个充电控制器错误,但是当字段为空时单击“发送”表单时,它不会显示任何错误。
我很乐意帮忙
提前致谢
控制器: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->library('form_validation');
}
public function Index()
{
redirect(base_url() . 'user/login/');
}
public function login()
{
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$data['title'] = 'Login';
$data['page'] = 'user_register_login';
$data['action'] = 'login';
$this->load->view('includes/main',$data);
}
else
{
redirect(base_url());
}
}
public function register()
{
$data ['action'] = 'register';
$data ['page'] = 'user_register_login';
$data ['title'] = 'הירשם למערכת';
$this->load->view('includes/main', $data);
}
public function reset_password()
{
$data ['action'] = 'reset_password';
$data ['page'] = 'user_register_login';
$data ['title'] = 'איפוס סיסמה';
$this->load->view('includes/main', $data);
}
}
观点:
<h1>משתמשים</h1>
<ul>
<li><a href="<?php echo base_url();?>/user/login/">התחבר/התנתק</a></li>
<li><a href="<?php echo base_url();?>/user/register/">הרשמה</a></li>
<li><a href="<?php echo base_url();?>/user/reset_password/">שכחתי סיסמה</a></li>
</ul>
<?= validation_errors(); ?>
<?= form_open(base_url() . 'user/' . $action . '/'); ?>
<?php if($action == 'login'): ?>
<label>Email: </label> <input type="text" name="email" size="20" /><br/>
<label>Password: </label> <input type="password" name="password" size="20" /><br/>
<input type="submit" name="submit" value="Login" />
<?php endif; ?>
<?php if ($action == 'register'): ?>
<h2> הירשם למערכת </h2>
<label>שם מלא: </label> <input type="text" name="name" id="name"><br>
<label>כתובת מייל: </label> <input type="text" name="email" id="email"><br>
<label>בחר סיסמה: </label> <input type="password" name="password" id="password"><br>
<label>חזור שוב על הסיסמה </label> <input type="password" name="password2" id="password2"><br>
<input type="submit" value="הירשם">
<?php endif; ?>
<?php if ($action == 'reset_password'): ?>
<h2> שכחתי סיסמה </h2>
<label>כתובת מייל: </label> <input type="text" name="email" id="email"><br>
<input type="submit" value="אפס סיסמה">
<?php endif; ?>
</form>
答案 0 :(得分:0)
我已经修复了您的问题亲爱的。请更正您的代码,如下所述
控制器:user.php(更改2个功能)
public function Index()
{
$data['title'] = 'Login';
$data['page'] = 'user_register_login';
$data['action'] = 'login';
$this->load->view('includes/main',$data);
}
public function login()
{
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
redirect(base_url());
}
}
查看:将以下行添加到文件user_register_login.php
<div id="validationError" style="width:100%;float:left;height:25px;float:left">
<?php echo validation_errors(); ?>
</div>
最重要的是检查你的base_url设置config / config.php $ config ['base_url']是否为localhost。