Welcome Guest, Not a member yet? Register   Sign In
Form validation with multiple forms in one view
#1

[eluser]Unknown[/eluser]
I have a view named editbox which is called from the box/edit controller. On the view there are several forms, e.g. one which calls the box/addFilter controller, which, after adding a filter or, if validation fails, not doing this redirects back to box/edit. If the form validation fails, no error message is displayed, probably because i use a redirect. What should I do?
#2

[eluser]TheFuzzy0ne[/eluser]
If you want to redirect and use an error message, there are two options available that I know of.

The first - my favourite- is to use flashdata to pass a message over to the next page, and display the message. This requires you to have the [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]session[/url] class loaded, and your user will need to have cookies enabled.

The second, is to simply redirect, and add an extra segment to the URI to let the controller that's receiving the redirect know there was an error, and display it. This only works if the controller you're redirecting to accepts a strict, set number of parameters. If your controller accepts a variable number of parameters, you might want to [url="http://ellislab.com/forums/viewthread/106502/"]check out the two functions I published today[/url], which will aid in passing a message over in the URI.

All the best!
#3

[eluser]mello.capinpin[/eluser]
I have the same problem as 'elektrowolf', I have two forms in a view that have identical fields, when I use form_error('name'), the error message appears on both forms.
#4

[eluser]TheFuzzy0ne[/eluser]
This is partly why it's considered bad practice to have two identically named form elements on the same page, even if they are within separate forms. You should really have a prefix for your form names as it will prevent these types of problem.

My problem was with my login form. I have a login form at the top of the page, and a page also containing a similar form. Prefixing them works, and you can have a hidden input names "prefix" to tell your code which form it's processing. I just decided not to show the login form in the header if the login page is showing.
#5

[eluser]mello.capinpin[/eluser]
yup! that solves my problem..




Theme © iAndrew 2016 - Forum software by © MyBB