PHP而不是jquery在成功codeigniter之后清除表单

PHP而不是jquery在成功codeigniter之后清除表单

本文介绍了使用PHP而不是jquery在成功codeigniter之后清除表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张注册表。成功后,我要删除 set_value 值并取消设置所有已发布的值。

I have a registration form. after success i want to remove set_value value and unset all posted value.

view.php

<?php echo validation_errors(); ?>
<?php if(isset($msg)){
     echo $msg;
} ?>
<form action="" method="post">
   <h5>Username</h5>
   <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
   <h5>Password</h5>
   <input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />
   <div>
       <input type="submit" value="Submit" />
   </div>
</form>

控制器功能.php

 $this->load->helper(array('form', 'url'));

 $this->load->library('form_validation');
 $this->form_validation->set_rules('username', 'Username', 'required');
 $this->form_validation->set_rules('password', 'Password', 'required');
 if ($this->form_validation->run() == FALSE){
      $data->msg='Please fill all field';
      $this->load->view('view',$data);
}else{
     $data->msg='success';
     unset($_POST);
     $this->load->view('view',$data);
}

我尝试但不起作用,也可以尝试

I try unset($_POST) but not worked, also try

  public function clear_field_data() {
    $this->_field_data = array();
    return $this;
  }

,但没有任何效果。我正在使用codeigniter 3.1.5 ...请帮助进行排序。

but nothing works. I am using codeigniter 3.1.5..Please help to sort out it.

推荐答案

我已经解决了自己的问题。

I solved my problem my self.

view.php

<?php echo validation_errors(); ?>
<?php if(isset($msg)){
 echo $msg;
} ?>
<form action="" method="post">
  <h5>Username</h5>
  <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
  <h5>Password</h5>
  <input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />
  <div>
     <input type="submit" value="Submit" />
  </div>
</form>

控制器功能.php

$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE){
  $data->msg='Please fill all field';
  $this->load->view('view',$data);
}else{
 $data->msg='success';
 $this->form_validation->clear_field_data();
 $this->load->view('view',$data);
}

MY_Form_validation.php

class MY_Form_validation extends CI_Form_validation {

public function __construct($config)
{
    parent::__construct($config);
}

public function clear_field_data() {
    $_POST = array();
    $this->_field_data = array();
    return $this;
}
}

问题已在新版本的CodeIgniter中解决。

And problem solved in new version codeIgniter.

这篇关于使用PHP而不是jquery在成功codeigniter之后清除表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:54