CodeIgniter Forums
Unset rule in Form Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Unset rule in Form Validation (/showthread.php?tid=94)



Unset rule in Form Validation - Isterklister - 11-04-2014

HI,
I need to unset rules and result in Form Validation helper.
How can I do that?

/Pelle


RE: Unset rule in Form Validation - benedmunds - 11-11-2014

Just set the rules based on what you need instead of unsetting what you dont need. You can do that using if/else and only setting what you need.


RE: Unset rule in Form Validation - RobertSF - 11-11-2014

(11-04-2014, 03:09 PM)Isterklister Wrote: I need to unset rules and result in Form Validation helper.

This will clear the entire form validation data, including rules, values, errors, etc.

Create a file called MY_form_validation.php in your application/libraries folder. In that file, put the following code:
PHP Code:
class MY_Form_validation extends CI_Form_validation {

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

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


When you want to clear the form validation data, just invoke the method, like this:
PHP Code:
$this->form_validation->clear_field_data(); 

That is useful when you want to process data and then show the same form again -- but blank -- to receive new data, like when you're adding one customer record after another.


RE: Unset rule in Form Validation - raenk - 05-07-2015

Since CI 3.0 I cant' get this to work. Also tried reset_validation() and I still get the same data in the form.

Any one else?


RE: Unset rule in Form Validation - carsten - 09-30-2015

I have the same problem. How can I solve it?

I have a view with the form and a controller with the validation methods. If I submit the form I don't get the form fields empty.