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

[HELP] 表单值,我这样获取不对吗?

[复制链接]
发表于 2009-9-10 10:56:13 | 显示全部楼层 |阅读模式
本帖最后由 dogwin 于 2009-9-10 15:11 编辑

controller/form.php
class Form extends Controller{
function Borm(){
  parent::Controller();
}
function index(){
  $this->load->helper('form','url');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('username','Username','callback_username_check');
  $this->form_validation->set_rules('password','Password','callback_password_check');
  $this->form_validation->set_rules('con_password','Password confrim','callback_con_password_check');
  if($this->form_validation->run()==FALSE){
   $this->load->view('myform');
  }else{
   $form_ps['username'] = $this->input->post('username');
   $form_ps['password'] = $this->input->post('password');
   $form_ps['con_password'] = $this->input->post('con_password');
   $this->load->view('formsuccess',$form_ps,FALSE);
  }
}
function username_check($str){
  if($str=='dogwin'){
   $this->form_validation->set_message('username_check','The %s filed can not be the word dogwin');
   return FALSE;
  }else{
   return TRUE;
  }
}
function password_check($ps){
  if($ps==""){
   $this->form_validation->set_message('password_check','Sorry!the password can not be NULL');
   return FALSE;
  }else{
   return TRUE;
  }
}
function con_password_check($con_ps){
  if($con_ps==""){
   $this->form_validation->set_message('con_password_check','Sorry!the confrim password can not be Null');
   return FALSE;
  }else{
   return TRUE;
  }
}
}
views/formsuccess.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<h3>The Form was successful!</h3>
<p><?php echo anchor('form','try it again!');?></p>
<?php echo "username=>".$username;?>
<?php echo "<br>password=>".$password;?>
<?php echo "<BR>con_password=>".$con_password;?>
</body>
</html>
views/myform.php
<html>
<head>
<title></title>
</head>
<body>
<?php //echo validation_errors();?>
<?php echo form_open('form');?>
<h5>username:</h5>
<input type="text" name='username' value="<?=set_value('username')?>"/><?php echo form_error('username');?>
<h5>assword</h5>
<input type="password" name='password' value="<?=set_value('password')?>"/><?php echo form_error('password');?>
<h5>assword confrim:</h5>
<input type="password" name='con_password' value="<?=set_value('con_password')?>"/><?php echo form_error('con_password');?>
<input type="submit" value='Submit'/>
</form>
</body>
</html>
这样传值是不是有问题啊?我想知道正确的方法应该怎么样传!谢谢了!

<!-2009-9-10 15:11:00-!>
$_POST实际上是传过去了,但受一个函数的影响没有正常显示。
在views/formsucces.php
<?php echo anchor('form','try it again!');?>
这是为什么?请朋友帮忙解释一下!
发表于 2009-9-10 11:22:50 | 显示全部楼层
你遇到什么问题了?有错误?
 楼主| 发表于 2009-9-10 14:21:03 | 显示全部楼层
2# Hex
就是不能传值。
发表于 2009-9-10 14:34:42 | 显示全部楼层
我没看出来问题~哎~
发表于 2009-9-10 14:35:32 | 显示全部楼层
class Form extends Controller{
function Borm(){
  parent::Controller();
}
发表于 2009-9-10 14:35:46 | 显示全部楼层
构造函数有问题吧
发表于 2009-9-10 14:39:12 | 显示全部楼层
5# kazaff

还是你眼力好!
 楼主| 发表于 2009-9-10 14:46:30 | 显示全部楼层
5# kazaff
谢谢,不过我改过来了。还是不能传值啊。
发表于 2009-9-10 15:29:14 | 显示全部楼层
没看懂楼主想说什么啊,什么叫不能传值?
发表于 2010-2-12 19:46:52 | 显示全部楼层
继续咨询楼主的问题 我也关注

本版积分规则