[eluser]edjon2000[/eluser]
Hi all
Sadly I have another set of newbie questions.
The Problem:
I have been trying to make sense of the form validation class, and how to apply it to a situation where there is more than one form in a view, but, I am running into the problem where, if I submit one form, validation fails on the other.
What I have done so far
I have spent the last week or so looking around these fine forums to try and find a demonstratable version I can adapt but, whilst I have found a few partial solutions, they do not go into enough depth as to how to apply them.
My Questions
1. If I am validating a form, should I set the form action to the controller method that originally displays the form, let's say I generate the form from a controller method called contact, or should I perform the validation in the contact method or perform it in the final method which could be something like feedback.
2. If I perform the validation in the feedback method, how can I redirect to the original view AND display the errors in the contact view.
Things I have seen
I found an interesting post from madmartigan1 that went as follows:-
Quote:LuckyFella73 - 19 December 2010 08:44 PM
Maybe you could set some if/else statemnts in your controller
and check which form was submitted. Set a hidden input field
for each form and check which form was send. Then in your
controller:
if ( isset($this->input->post('form_1')) and strlen($this->input->post('form_1'))>1)
{
// validate form 1
}elseif( isset($this->input->post('form_2')) and strlen($this->input->post('form_2'))>1)
{
// validate form 2
}elseif( isset($this->input->post('form_3')) and strlen($this->input->post('form_3'))>1)
{
// validate form 3
}
Didn’t test that but it should work.
This would work, but $this->input->post() will return false if it’s empty or not set, so all you would need is:
if ($this->input->post('form_1'))
{
// validate form 1
}
if ($this->input->post('form_2'))
{
// validate form 2
}
I use this sometimes when I have 2 or more forms that post to the same controller.
But I cannot seem to get that to work, because I am not sure how to implement madmartigan1's solution, I did ask in the thread but, it was quite old
Any advice would be greatly appreciated
Jon