php - 在codeigniter中使用form_error函数后,html消失
问题描述
我正在尝试在我的 html 表单中添加表单错误消息。问题存在于第一个视图中。在用户函数中,html 从我开始使用的地方消失form_error()
。我的原始表单设计是这样的:我的原始表单
,但在form_error
第一个输入下添加后:我的表单错误图像
这是我的 html 代码
<div class="form-group">
<label for="name"><i class="zmdi zmdi-account material-icons-name"></i></label>
<input type="text" name="username" id="name" placeholder="Your Name" />
<?php echo form_error('username','<p class="p_errror" id="name_error_p">','</p>') ?>
</div>
<div class="form-group">
<label for="email"><i class="zmdi zmdi-email"></i></label>
<input type="text" name="email" id="email" placeholder="Your Email"/>
<?php echo form_error('email','<p class="p_errror" id="name_error_p">','</p>') ?>
</div>
这是我的控制器
<?php
class Register extends CI_Controller
{
public function user()
{
$this->load->view('files/registration/signup');
}
public function login()
{
$this->load->view('files/registration/login');
}
public function description()
{
$this->load->view('files/registration/description');
}
public function registerMe()
{
$this->load->helper('form','url');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|alpha|max_length[15]');
$this->form_validation->set_rules('pass', 'Password', 'required',
array('required' => 'You must provide a %s.')
);
$this->form_validation->set_rules('re_pass', 'Confirm Password', 'required|matches[pass]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run()===FALSE) {
$this->load->view('files/registration/signup');
}
else
{
$this->load->model('RegisterUser');
$this->RegisterUser->registerme($_POST);
}
}
}
?>
解决方案
您还需要在注册功能中加载表单助手。 form_error
是 form_helper 中的一个函数。(这对于具有表单视图的其他功能也是必需的)
public function user()
{
$this->load->helper('form');
$this->load->view('files/registration/signup');
}
html 消失,因为有 php 错误。发生这种情况时检查您的错误日志或将 codeigniter 环境更改为 index.php 中的开发
推荐阅读
- java - 没有修饰符(默认)的类不能访问声明为公共的子类?爪哇
- python - Django,带有非ascii文本的csv文件在windows excel文件中不可读
- javascript - 在Javascript中查找水平滚动条的拇指宽度
- java - 新计算机上 DDE 中的 Java 编译器错误,在旧计算机上运行良好
- java - 为什么这里的错误出现在三元运算符中?
- php - Laravel Queue - 在某些情况下防止作业重试
- wordpress - Facebook Sharer 无法获取 og:image 虽然它存在于元标记中(worpress - woocomerce)
- android - 为什么我的应用程序将其数据发送到另一个 Firebase 实时数据库
- xml - 是否可以在 Jenkins 测试作业中下载原始 xml 文件
- ios - LaunchScreen.storyboard 中的活动指示器不旋转。(IOS启动屏幕问题)