加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Codeigniter validation_errors()总是返回空

发布时间:2020-12-13 22:45:50 所属栏目:PHP教程 来源:网络整理
导读:我有一个简单的表单添加到我的数据库与以下验证规则. “form”在autoload.php中. 每当任何验证规则被破坏时,页面都不显示错误输出,当没有任何错误输出被破坏时,表单按预期进行. 这是我的控制器功能 public function add(){ $this-load-library('form_validat
我有一个简单的表单添加到我的数据库与以下验证规则. “form”在autoload.php中.

每当任何验证规则被破坏时,页面都不显示错误输出,当没有任何错误输出被破坏时,表单按预期进行.

这是我的控制器功能

public function add()
{

    $this->load->library('form_validation');
    $this->load->library('layout');
    // field name,error message,validation rules
    $this->form_validation->set_rules('type','Type','required|xss_clean');
    $this->form_validation->set_rules('title_type','Title type','required|xss_clean');
    $this->form_validation->set_rules('first_name','First name','trim|required|min_length[1]|max_length[150]|xss_clean');
    $this->form_validation->set_rules('surname','Surname','trim|required|min_length[1]|max_length[150]|xss_clean');
    $this->form_validation->set_rules('job_title','Job title','trim|min_length[5]|max_length[300]required|xss_clean');
    $this->form_validation->set_rules('office_number','Office number','trim|min_length[2]|max_length[11]|xss_clean');
    $this->form_validation->set_rules('telephone','Telephone','trim|numeric|xss_clean');
    $this->form_validation->set_rules('email','Email','trim|valid_email|xss_clean');
    $this->form_validation->set_rules('website','Website','trim|prep_url|xss_clean');
    $this->form_validation->set_rules('background','Background','trim|xss_clean');


    $data = array(
        'title' => 'Add staff member'
    );

    if ($this->form_validation->run() == FALSE) { //Was errors

        $this->session->set_flashdata('message','You missed some details,please try again.');

        $this->layout->load('default','add_person',$data);
    } else {
        $this->people_model->add_person();
        $this->layout->load('default','added_person',$data);
    }


} //add

在我的形式视图中,我有

<?php echo validation_errors('<p class="msg msg-error">') ?>

任何人都可以看到我做错了什么,我已经尝试了我能想到的一切.

验证validation_errors()的var_dump给出

string '' (length=0)

编辑:奇怪的是,如果我交换这两行,我得到:

$this->load->library('form_validation');
    $this->load->library('layout'); //lib code http://pastebin.com/K1rBV512

Message: Undefined property: People::$form_validation

Filename: controllers/people.php

Line Number: 27

解决方法

您需要将$data数组传递给模型.所有输入都需要从VIEW页面获取POST.您没有显示任何特定错误,因此很难诊断您的问题.

确保你在你的MODEL中发布这样的所有输入:

`'first_name' => $this->input->post('first_name'),`

在你看来:

<?php echo validation_errors('<p class="msg msg-error">') ?>

在您的视图中将其更改为:

<p class="msg msg-error"><?php echo validation_errors(); ?></p>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读