Welcome Guest, Not a member yet? Register   Sign In
Form Validation
#13

(08-14-2015, 08:40 AM)mariek Wrote: my controller method & view concentrate several forms (5) which I don't want to update at the same time.
For instance, I have a form with personnal info, another one with password, etc. I don't want to put them on a different page, I think it's not user-friendly to make him click time and time again.
So I made a "save" controller method for each form, but a single controller method to display the whole.
What would you do instead ?

None of this really tells me why you need a redirect. Instead of posting each form to a different method on the controller, you can post them all back to the same controller method which was used in the first place, with different names on the submit buttons (or they could even have the same name but different values). In the beginning of the controller method you can determine which form was submitted and call the "save" controller method for that form. The "save" method would simply return (usually true/false, but you may need something more complicated, depending on how you handle errors) to the main method.

Even if you call the "save" methods from the form, you can still send the code back through the original method to display the form (without redirecting), but you would end up displaying the same view from multiple URLs (based on whatever they last attempted to save). You would also have to ensure the original method could distinguish between the two cases (if the original method is loading data from the database), or you can call a separate method from the original method and the "save" methods to display the view.

While avoiding redirects is certainly a good thing for your users where possible, there are conditions under which the user is more or less conditioned to expect them and will sometimes be confused if they don't occur, and a successful submission of a form is often one of them. This means that submitting your form to a different URL doesn't have to be a problem, even if their ultimate destination when the form is submitted successfully is back to the original URL from which they started the process.
Reply


Messages In This Thread
Form Validation - by ignitedcms - 08-04-2015, 11:11 AM
RE: Form Validation - by mwhitney - 08-04-2015, 01:36 PM
RE: Form Validation - by Diederik - 08-04-2015, 03:02 PM
RE: Form Validation - by ignitedcms - 08-04-2015, 03:40 PM
RE: Form Validation - by Diederik - 08-04-2015, 10:36 PM
RE: Form Validation - by ignitedcms - 08-05-2015, 12:08 AM
RE: Form Validation - by mwhitney - 08-05-2015, 07:26 AM
RE: Form Validation - by Diederik - 08-05-2015, 01:43 AM
RE: Form Validation - by Wouter60 - 08-05-2015, 06:50 AM
RE: Form Validation - by CroNiX - 08-05-2015, 07:20 AM
RE: Form Validation - by ignitedcms - 08-05-2015, 11:55 AM
RE: Form Validation - by mariek - 08-14-2015, 08:40 AM
RE: Form Validation - by mwhitney - 08-14-2015, 09:54 AM
RE: Form Validation - by mariek - 08-17-2015, 12:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB