表单验证不出来提示信息!!
$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');
$this->form_validation->set_rules('u_pwd', '账号密码', 'required');
$this->form_validation->set_rules('re_pwd', '确认密码', 'required|matches');
$this->form_validation->set_rules('u_nick', '账号昵称', 'required|is_unique');
$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');
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();
}
}
}
请高手指点!!! 报什么错?你这个看起来没问题。 form_open('users/adduser') 应该是路径的问题 Hex 发表于 2012-6-17 09:54 static/image/common/back.gif
报什么错?你这个看起来没问题。
什么错误也没有,也没有提示,echo ($this->form_validation->run() == FALSE).'----';这个地方。输出的是1----,意思是验证不通过,但没有任何提示啊!! ilci 发表于 2012-6-17 12:23 static/image/common/back.gif
应该是路径的问题
一直执行的是这块代码
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 11:30 static/image/common/back.gif
form_open('users/adduser')
这样也不行,我的这个网站的根目录本身是localhost/这个路径的,这样修改的我原来的效果是一样的!! 贴代码,都贴出来。 Hex 发表于 2012-6-17 15:34 static/image/common/back.gif
贴代码,都贴出来。
我都贴了啊,我把整个类都贴了,还要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%"> </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> </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> </td>
</tr>
<tr>
<td height="37" align="center">用户性别</td>
<td>
<input name="u_sex" type="radio" id="radio" value="1" checked="checked" />
帅哥
<input type="radio" name="u_sex" id="radio2" value="0" />
美女
</td>
<td> </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> </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> </td>
</tr>
<tr>
<td height="37" align="center">验 证 码</td>
<td><input name="code" type="text" id="code" size="10" maxlength="4" /></td>
<td> </td>
</tr>
<tr>
<td height="40"> </td>
<td>
<input name="button" type="submit" class="btnsty" id="button" value="立即注册" />
<input name="button2" type="button" class="btnsty" id="button2" value="我有账号直接登录" /></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php echo validation_errors(); ?>
这个是view的代码 y284663247 发表于 2012-6-17 15:37 static/image/common/back.gif
我都贴了啊,我把整个类都贴了,还要view的吗?
看了一下,你这个确实很奇怪,代码没看出问题。
我是无能为力了。。。呵呵