【问题标题】:Codeigniter form validation does not show errors [duplicate]Codeigniter 表单验证不显示错误 [重复]
【发布时间】:2016-02-18 12:38:18
【问题描述】:

Codeigniter 表单验证不显示错误 每当我在 codeigniter 中提交给定表单中的不完整字段时,它都不会显示任何错误,而是将我重定向到 about:blank 页面 查看:view/forms.php

<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
<input type="text" name="username" value="" size="50" />

<h5>Password</h5>
<input type="password" name="password" value="" size="50" />

<h5>Password Confirm</h5>
<input type="password" name="passconf" value="" size="50" />

<h5>Email Address</h5>
<input type="email" name="email" value="" size="50" />

<div><input type="submit" value="Submit" /></div>

</form>

</body>
</html>

控制器:

<?php
class Form extends CI_Controller {
  function index()
    {
    /*Load the form validation helpers*/
        $this->load->helper(array('form', 'url'));
    /*Load the form validation helpers*/
        $this->load->library('form_validation');
    /*Set the form validation rules*/
    $this->form_validation->set_rules('username', 'Username', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required');
    $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
    $this->form_validation->set_rules('email', 'Email', 'required');
    /*Check if the form passed its validation */
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('forms');
        }
        else {
            $this->load->view('formsuccess');
        }
    }
}
?>

目前我不打算进行数据库验证,只检查所有字段是否已填写,如果是,则转到成功页面或在同一页面上显示验证错误!

【问题讨论】:

    标签: php forms codeigniter


    【解决方案1】:

    认为我的 xampp 有问题,因为我将文件夹转移到我的另一台笔记本电脑,它在那里完美运行!将尝试重新安装 xampp

    【讨论】:

      【解决方案2】:

      尝试在视图中添加required

      <input type="text" name="username" value="" size="50" required/>
      
      <h5>Password</h5>
      <input type="password" name="password" value="" size="50" required/>
      
      <h5>Password Confirm</h5>
      <input type="password" name="passconf" value="" size="50" required/>
      
      <h5>Email Address</h5>
      <input type="email" name="email" value="" size="50" required/>
      

      控制器-

      function __construct()
          {
              parent::__construct();
      
               $this->load->helper(array('form', 'url'));
              $this->load->library('form_validation');
      
          }
      
          $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
      

      也要检查您的 .htaccess 文件

      【讨论】:

      • 那是前端验证,那么codeigniter验证库有什么用!即使这样,也没有加载成功页面,而是:加载空白页面
      • 我已经编辑了帖子,尝试编辑控制器,你的form_open(form)和你的加载视图是forms实际上是不同的?
      • 没有相同的结果 :( 那是因为 forms.php 是视图文件,而 form.php 是控制器
      • 你是什么意思它只显示空白页 i。 E 关于空白
      • 认为我的 xampp 有问题,因为我将文件夹转移到我的另一台笔记本电脑,它在那里完美运行!将尝试重新安装 xampp
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-09-05
      • 2012-01-12
      • 1970-01-01
      相关资源
      最近更新 更多