Clear form data after success codeigniter using php not jquery

前端 未结 2 1325
面向向阳花
面向向阳花 2021-01-23 01:22

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

view.php



        
2条回答
  •  暖寄归人
    2021-01-23 01:48

    I solved my problem my self.

    view.php

    
    
    
    Username
    Password

    Controller function.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;
    }
    }
    

    And problem solved in new version codeIgniter.

提交回复
热议问题