用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6416|回复: 24
收起左侧

表单验证不出来提示信息!!

  [复制链接]
发表于 2012-6-17 09:34:34 | 显示全部楼层 |阅读模式
$config['enable_query_strings'] = TRUE;这个设置成True,form_open('c=users&m=adduser'),执行下面的代码可以显示表单验证提示。
但$config['enable_query_strings'] = FALSE;form_open('/users/adduser')为什么就不出来验证提示啊,高手指点一下。

代码如下:
class Users extends CI_Controller {

       
        public function index()
        {
                $this->load->view('welcome_message');
        }       
       
        public function register()
        {
                $data['main_content'] = 'register';
                $this->load->view('include/template',$data);
        }
       
        public function adduser()
        {
                //$this->lang->load('form_validation', 'chinese');
                $this->load->library('form_validation');
               
                $this->form_validation->set_rules('u_email', '电子邮箱', 'required|valid_email|is_unique[users.u_email]');
                $this->form_validation->set_rules('u_pwd', '账号密码', 'required');
                $this->form_validation->set_rules('re_pwd', '确认密码', 'required|matches[password]');
                $this->form_validation->set_rules('u_nick', '账号昵称', 'required|is_unique[users.u_nick]');
                $this->form_validation->set_rules('u_sex', '用户性别', 'required');
                $this->form_validation->set_rules('province', '所在省市', 'required');
                $this->form_validation->set_rules('city', '所在市区', 'required');
                $this->form_validation->set_rules('code', '验 证 码', 'required|exact_length[4]');
               
                if($this->form_validation->run() == FALSE)
                {                               
                        echo ($this->form_validation->run() == FALSE).'----';
                        print_r(validation_errors());
                        //echo $this->validation->error_string();
                        //$this->load->view('register');
                        $this->register();
                       
                }else{
                       
                        $this->load->model(user);
                        $this->user->adduser();
                       
                }
}
}
请高手指点!!!
发表于 2012-6-17 09:54:35 | 显示全部楼层
报什么错?你这个看起来没问题。
发表于 2012-6-17 11:30:44 | 显示全部楼层
form_open('users/adduser')
发表于 2012-6-17 12:23:00 | 显示全部楼层
应该是路径的问题
 楼主| 发表于 2012-6-17 15:25:50 | 显示全部楼层
Hex 发表于 2012-6-17 09:54
报什么错?你这个看起来没问题。

什么错误也没有,也没有提示,echo ($this->form_validation->run() == FALSE).'----';这个地方。输出的是1----,意思是验证不通过,但没有任何提示啊!!
 楼主| 发表于 2012-6-17 15:26:50 | 显示全部楼层
ilci 发表于 2012-6-17 12:23
应该是路径的问题

一直执行的是这块代码

if($this->form_validation->run() == FALSE)
                {                              
                        echo ($this->form_validation->run() == FALSE).'----';
                        print_r(validation_errors());
                        //echo $this->validation->error_string();
                        //$this->load->view('register');
                        $this->register();
                       
                }
但就是没有提示
 楼主| 发表于 2012-6-17 15:29:17 | 显示全部楼层
貝殼 发表于 2012-6-17 11:30
form_open('users/adduser')

这样也不行,我的这个网站的根目录本身是localhost/这个路径的,这样修改的我原来的效果是一样的!!
发表于 2012-6-17 15:34:37 | 显示全部楼层
贴代码,都贴出来。
 楼主| 发表于 2012-6-17 15:37:18 | 显示全部楼层
Hex 发表于 2012-6-17 15:34
贴代码,都贴出来。

我都贴了啊,我把整个类都贴了,还要view的吗?

<div class="reg_head"></div>
<div class="reg_main">
  <h2>注册</h2>
  <!-- <form id="form1" name="form1" method="post" action="/users/adduser"> -->
  <?php echo form_open('users/adduser')?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="24%" height="37" align="center">电子邮箱</td>
        <td width="43%">
          <input name="u_email" type="text" id="u_email" size="40" maxlength="40" />
        </td>
        <td width="33%">&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center"><dl>
          <dt>账号密码</dt>
        </dl></td>
        <td><input name="u_pwd" type="password" id="u_pwd" size="40" maxlength="40" /></td>
        <td><?php echo form_error('u_pwd'); ?></td>
      </tr>
      <tr>
        <td height="37" align="center">确认密码</td>
        <td><input name="re_pwd" type="password" id="re_pwd" size="40" maxlength="40" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center">账号昵称</td>
        <td><input name="u_nick" type="text" id="u_nick" size="40" maxlength="40" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center">用户性别</td>
        <td>
          <input name="u_sex" type="radio" id="radio" value="1" checked="checked" />
          帅哥
          &nbsp;
          <input type="radio" name="u_sex" id="radio2" value="0" />
          美女
        </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center">用户生日</td>
        <td>
          <select name="b_year" id="b_year">
          </select>
          <select name="b_month" id="b_month">
          </select>
          <select name="b_day" id="b_day">
          </select>
        </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center">所在地区</td>
        <td><select name="province" id="province">
        </select>
          <select name="city" id="select5">
          </select>
          <select name="cityzone" id="select6">
        </select></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="37" align="center">验 证 码</td>
        <td><input name="code" type="text" id="code" size="10" maxlength="4" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="40">&nbsp;</td>
        <td>
          <input name="button" type="submit" class="btnsty" id="button" value="立即注册" />
          &nbsp;
<input name="button2" type="button" class="btnsty" id="button2" value="我有账号直接登录" /></td>
        <td></td>
      </tr>
    </table>
  </form>
</div>
<?php echo validation_errors(); ?>

这个是view的代码
发表于 2012-6-17 15:42:13 | 显示全部楼层
y284663247 发表于 2012-6-17 15:37
我都贴了啊,我把整个类都贴了,还要view的吗?

看了一下,你这个确实很奇怪,代码没看出问题。
我是无能为力了。。。呵呵

本版积分规则