Welcome Guest, Not a member yet? Register   Sign In
form validation class help
#1

[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 ?
#2

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

[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.
#4

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

[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');
        }
    
    }
}
?>
#6

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

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

Thanks mate :-)
#8

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




Theme © iAndrew 2016 - Forum software by © MyBB