CodeIgniter Forums
form validation class help - 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 class help (/showthread.php?tid=25752)



form validation class help - El Forum - 12-23-2009

[eluser]manitoon[/eluser]
I was running the example given in the form validation tutorial and I am getting this problem that

<?php echo validation_errors(); ?> shows errors even if the form is opened first time. It always shows errors

how can i fix this issue ?


form validation class help - El Forum - 12-23-2009

[eluser]flaky[/eluser]
check if you have
Code:
$this->form_validation->run()
inside contructor, if it's there remove it from there.


form validation class help - El Forum - 12-23-2009

[eluser]manitoon[/eluser]
nope there is no
$this->form_validation->run()

in the constructor.

I guess i have to send a variable like "$form_submited" and then check it to whether show errors or not.


form validation class help - El Forum - 12-23-2009

[eluser]flaky[/eluser]
put the code here


form validation class help - El Forum - 12-23-2009

[eluser]manitoon[/eluser]
Code:
<?php

class Customers extends Controller {

    function Customers()
    {
    
        parent::Controller();    
    }
    
    function index()
    {
        
        
        $this->view->assign('process',$this->input->post('process'));
        
        $this->load->helper(array('form'));
        $this->load->library('form_validation');
        $this->form_validation->set_rules('FirstName', 'firstname', 'required');
        $this->form_validation->set_rules('LastName', 'lastname', 'required');
        
    
        if ($this->form_validation->run() == TRUE)
        {
            // using smarty templates
            $this->view->show('customers');
        }
        else
        {
                // in both cases i have to show the same page
            $this->view->show('customers');
        }
    
    }
}
?>



form validation class help - El Forum - 12-23-2009

[eluser]flaky[/eluser]
well your code is in the index, so anytime the controller is called the validation is run


form validation class help - El Forum - 12-23-2009

[eluser]manitoon[/eluser]
oooh ok, now i understand.

Thanks mate :-)


form validation class help - El Forum - 12-23-2009

[eluser]flaky[/eluser]
You should check if the submit button has been clicked. That way you can prevent the errors from appearing