验证错误不净到Codeigniter中的Flashdata



我正在尝试使用codeigniter中的flashdata为我的表单设置验证错误,但我在视图中看不到错误,这是我的视图代码部分。我已经阅读了与此问题相关的其他相关问题,但没有找到解决方案!

<?php if($this->session->flashdata('errors')): ?>
<?php echo $this->session->flashdata('errors');?>
<?php endif; ?>
<?php $attributes = array('id'=>'admin_login','class'=>'form-horizontal'); ?>
<?php echo form_open('admin/login', $attributes); ?>
<div class="form-group">
<?php
$lbl = array('class'=>'col-sm-12 col-lg-12 col-md-12 col-xs-12 control-label');
echo form_label('Email','admin_login',$lbl); ?>
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'form-control col-sm-12 col-lg-12 col-md-12 col-xs-12',
'name'=> 'email',
'placeholder'=>'Enter your email'
); ?>
<?php echo form_input($data); ?>
</div>
</div>
<div class="form-group">
<?php
echo form_label('Password','admin_login',$lbl); ?>
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'form-control',
'name'=> 'password',
'placeholder'=>'Password'
); ?>
<?php echo form_password($data); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'btn btn-success btn-md center mt-2',
'name'=> 'submit',
'placeholder'=>'Password',
'value'=>'LOGIN',
'type'=>'submit'
); ?>
<center>
<?php echo form_submit($data); ?>
</center>
</div>
</div>
<?php echo form_close(); ?>

这是我的控制器部分,它是"管理员"方法名称的名称,名称是登录名

public function login(){
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('password','Password','required');
// check the form has any error (any miss of rules we set in above codes
if($this->form_validation->run() == FALSE){
$this->session->set_flashdata('errors', 
validation_errors());
//              $this->session->set_flashdata('name','Your message');
//              $errors = validation_errors();
//              $this->session->set_flashdata('form_error', $errors);
//              $this->session->set_flashdata('name','Your message');
//              $data = array('errors'=> validation_errors());
//              set_userdata() is regular way to set session, it need manually unset, there for we use flashdata
//              $this->session->set_flashdata($data);
}else{
echo "its all good";
}
}

我尝试了很多代码,我注释掉了到目前为止我使用的代码。我在自动加载部分会话库中设置也$autoload['libraries'] = array('database','form_validation','session');

请告诉我这里有什么问题。

请尝试使用以下代码。

public function login(){
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run() == true){
echo "its all good";
}else{
$this->session->set_flashdata('errors', validation_errors());
}
$this->load->view('Your View Page');
}

相关内容

  • 没有找到相关文章

最新更新