Welcome Guest, Not a member yet? Register   Sign In
Form Validation shows error before submitting form
#1

[eluser]iateaduck[/eluser]
Hey, I'd really appreciate if anyone could help me figure out why this is going on, or even help me fix the problem.

Basically, I have a multi-step form. It starts at:

www.mydomain.com/formcontroller/step1 (where step1 is the name of the function)

there's no problem with the form there. validation works as expected. the first time that this is run:
if ($this->form_validation->run() == FALSE)
validation_errors() returns nothing, because it somehow knows that you havent submitted the form yet (anyone know how?)
and that's correct/expected behavior. if i actually click "next step" to submit the form, THEN the form errors will show up in form_validation if there are any. again, this is correct.

however, i go on to:
www.mydomain.com/formcontroller/step2
and validation_errors() automatically already runs through the rules (without clicking submit/next button). This means that when i get to step 2, the errors show up even before the user has a chance to enter values.

my code looks like this (these functions are in the same controller):

function step1()
{
$this->form_validation->set_rules('blahfield', 'Meow cats', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('step1_view');
}
else
{
// go to second step
redirect('formcontroller/step2');
}
}

function step2()
{
$this->form_validation->set_rules('zingfield', 'Woof cats', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('step2_view');
}
else
{
// go to finish step
redirect('formcontroller/step3');
}
}


as you can see, they are pretty much identical. but for some reason step2 displays errors before the user can submit. any advice? the view files are also pretty mcuh the same ones as the ones in the guide: http://ellislab.com/codeigniter/user-gui...ation.html

thanks,
eatingaduck


Messages In This Thread
Form Validation shows error before submitting form - by El Forum - 02-25-2011, 09:24 PM
Form Validation shows error before submitting form - by El Forum - 02-25-2011, 11:19 PM
Form Validation shows error before submitting form - by El Forum - 02-27-2011, 02:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB