zhulicong 发表于 2011-8-24 09:40:23

CI的表单验证类,将规则写入配置文件中,出现错误!

本帖最后由 zhulicong 于 2011-8-24 10:25 编辑

如下规则用户用户注册:
在application/config文件夹中创建 form_validation.php文件,代码如下

$config=array(
         array(
            'field'   => 'username_reg',
            'label'   => '用户名me',
            'rules'   => 'required|min_length|max_length|callback_username_check'
         ),
         array(
            'field'   => 'password_reg',
            'label'   => 'Password',
               'rules'   => 'required|min_length|max_length'
         ),
            array(
               'field'   => 're_password_reg',
               'label'   => 'Password Confirmation',
               'rules'   => 'required|matches'
            )
         );


但是为什么现在我打开任何一个网页,这些信息都显示在页面上部?而对于真正用户注册,似乎么有起到作用。。。

截图如下:



jeongee 发表于 2011-8-24 09:44:13

你可以贴出你更多的代码

zhulicong 发表于 2011-8-24 09:56:42


102    function reg_check(){
103       if ($this->form_validation->run() == FALSE){
104          $this->load->view('reg');
105 //       redirect('welcome/reg');    //不符合规则,重新返回注册界面
106       }else {
107          $data = array(
108             'username' => $this->input->post('username_reg'),
109             'password' => MD5($this->input->post('password_reg'))
110          );
111          $this->db->insert('user',$data);
112          redirect('welcome/index');   //符合规则,将信息输入数据库,并且返回登陆页面
113
114
115       }
116
117    }


该reg_check()函数用户用户注册检验的一个controller



17   <body>
18      <div>
19         <fieldset>
20         <legend>用户注册</legend>
21         <?php echo validation_errors();?>
22         <?php echo form_open('welcome/reg_check');?>
23         <p>
24            <label for="username" class="label">用 户 名 :</label>
25            <input id="username_reg" name="username_reg" type="text" class="input" />
26         <p/>
27
28         <p>
29            <label for="password" class="label">密   码:</label>
30            <input id="password_reg" name="password_reg" type="password" class="input" />
31         <p/>
32
33         <p>
34            <label for="password" class="label">重复密码:</label>
35            <input id="re_password_reg" name="re_password_reg" type="password" class="input" />
36         <p/>
37
38
39         <p align="center">
40         <input type="submit" name="submit" value="确 定" class="left" />
41         </p>
42       </fieldset>
43      </div>
44   </body>
45</html>


以上是我view里面 reg.php代码。用户显示注册页面

jeongee 发表于 2011-8-24 10:04:48

zhulicong 发表于 2011-8-24 09:56 static/image/common/back.gif
该reg_check()函数用户用户注册检验的一个controller




看上去那个文件没有被解析一样,你是不是用的短标记哦,就是那个配置文件的开始你是不是用的<?而不是<?php

zhulicong 发表于 2011-8-24 10:19:54

jeongee 发表于 2011-8-24 10:04 static/image/common/back.gif
看上去那个文件没有被解析一样,你是不是用的短标记哦,就是那个配置文件的开始你是不是用的 ...

饿。。我知道原因了。。。。
应该是这样。。


1 <?php
2 $config=array(
3         array(
4            'field'   => 'username_reg',
5            'label'   => '用户名me',
6            'rules'   => 'required|min_length|max_length|callback_username_check'
7         ),
8         array(
9            'field'   => 'password_reg',
10            'label'   => 'Password',
11            'rules'   => 'required|min_length|max_length'
12         ),
13         array(
14            'field'   => 're_password_reg',
15            'label'   => 'Password Confirmation',
16            'rules'   => 'required|matches'
17         )
18      );
19 ?>


原来第一行是需要加上<?php 的。。我没有加。。。所以导致错误了。。。
谢谢这位朋友啊。。。
还有,帖子如何结贴啊?我怎么没有看到结贴的按钮呢?

jeongee 发表于 2011-8-24 10:21:24

zhulicong 发表于 2011-8-24 10:19 static/image/common/back.gif
饿。。我知道原因了。。。。
应该是这样。。



自己编辑改分类
页: [1]
查看完整版本: CI的表单验证类,将规则写入配置文件中,出现错误!