CodeIgniter Forums
Form Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form Validation (/showthread.php?tid=28673)



Form Validation - El Forum - 03-18-2010

[eluser]iamdadude[/eluser]
Hey,

I looked through the documentation for the form validation library and I'm wondering if there's a way you can check if a field is valid instead of just the whole form.

For example, if I want the whole form to be validated I would do
$this->form_validation->run();

What if I just wanted to see if $_POST['email'] is valid though? How do I go about doing that?

Thanks for any help in advance!


Form Validation - El Forum - 03-18-2010

[eluser]Kamarg[/eluser]
In system/application/MY_Form_validation.php
Code:
class MY_Form_validation extends CI_Form_validation {
    function clear_rules() {
        $this->_field_data  = array();
        $this->_error_array = array();
        $this->_error_messages = array();
    }
}

In your controller set the rules to check $_POST['email'] and run the validation. If you then need to run a different set of validation, call clear_rules() and set the new validation rules.


Form Validation - El Forum - 03-18-2010

[eluser]iamdadude[/eluser]
It would be nice if $this->form_validation->run($_POST['email']); worked haha