|
本帖最后由 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!');?>
这是为什么?请朋友帮忙解释一下! |
|