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

Thanks I'm going to remove all redirect then and load the views in the form validation class along with server side checking
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#12

I "reopen" this topic, I was trying to make form_validation work after a redirection.
I understand this is a waste of resource, but here's the point : 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 ?

Thanks for your help.
Reply
#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
#14

Thanks a lot mwhitney, I'm not sure I understood everything you told me the way you wanted to explain it (english is not my first language), but it gave me ideas : I can handle it with routes sending to a single controller with an extra parameter, I can use rules stored in a config file and I can use private controllers.

I started to program 2 forms before your answer and I have to many duplicate lines, if I have to change a thing on my view, I'll have to duplicate the changes on 4 ou 5 methods. My way is just not maintainable.

Again, thank you for your help.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB