提供了哦,添加了一个username_check函数,但是每次都报错,不知道怎么通过form_open()函数把表单里输入的值传递给这个函数
public function username_check($str)
{
if($str=='aaaaa')//比较输入的用户名是否存在
{
$this->form_validation->set_message('username_check','用户名已存在!');
return FALSE;
}
else
{
return TRUE;
}
}
如果是form_open('form')的话,它不是会自动调用index()函数吗,就不能回调自己写的函数了 回复 9# qi_ruo
我在发帖的时候已经把username_check()函数写上了,可是不知道怎么通过form_open()函数把表单里输入的值传递给username_check()函数。或者有其他的办法把输入的值传递给username_check()函数吗? 回复 9# qi_ruo
可以了,真的是form_open('form')就可以了,但是有点点不明白,怎么会执行username_check()函数...明白了,在set_rules()规则里面,所以才称回调自己的函数,才不用在url片段里面加上username_check()方法!开始也有矛盾,都执行username_check()方法了怎么还能执行index()方法跳转到登录成功后的界面,现在才有点点明白了...谢谢你们了,以后还有不懂得地方请多多指教哈! 回复 8# rockics
我还有一个帖子,也解决了,本来想自己分类的,可是不知道是不能还是不会,所以麻烦版主帮帮分分类啊!!! 我也碰到同样的问题...回调函数执行的时候正确之后不能跳到正确的页面
//添加
function add_save(){
// $this->form_validation->set_rules('title', '标题', 'required');
// $this->form_validation->set_message('required', '%s名称不能为空');
// if($this->form_validation->run()==TRUE){
if($this->form_validation->run('signup')==TRUE){
echo 1;
$date = array(
'title' =>$this->input->post('title')
,'neirong' =>$this->input->post('neirong')
,'datetime' => time()
);
$this->mlyb->insert('lyb',$date);
}
// redirect(site_url('lyb/index'));
// $this->load->view('lyb_index');
$this->index();
}
//自定义错误提示
function null_check($str){
echo $str;
if(empty($str)){
echo $str;
$this->form_validation->set_message('null_check', '%s不能为空');
return FALSE;
}
else{
echo 1;
return TRUE;
}
}
还有个问题就是回调之后不能重新填充表单
<table>
<tr>
<td colspan="2">添加留言板</td>
</tr>
<tr>
<td >标题:</td>
<td><input type="text" name='title' value="<?php echo set_value('title'); ?>" id='title' /><?php echo form_error('title'); ?></td>
</tr>
<tr>
<td>内容:</td>
<td><textarea rows="5" cols="20" name="neirong" id="neirong"></textarea></td>
</tr>
<tr>
<td colspan="2"><inputtype="submit" value="保存"/></td>
</tr>
</table> 上面的问题我弄好了...是配置的时候写多了...
$config = array(
'signup' => array(
array(
'field' => 'title',
'label' => '标题',
'rules' => 'callback_null_check'
),
array(
'field' => 'neirong',
'label' => '内容',
'rules' => 'callback_null_check'
)
)
);
翻手册才知道..这里不能多写
还有个问题...如果自己写回调函数..是不是只能写在当前的class里面...能自己单独写个回调的class...方便调用吗...毕竟很多地方可能会用到同一个回调函数
页:
1
[2]