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

(This post was last modified: 05-26-2016, 09:52 AM by cartalot.)

(05-22-2016, 05:23 PM)albertleao Wrote: I personally disagree with putting form validations in models. Form validations, as stated, are for forms, which is found in a view which is handled by controllers. Database validation in models is fine, but if you are using your models with different apps without a front end, things can get hairy quickly.

Wouldn't the apps still be running through a Controller?
So here is why i don't like form validation in Controllers - and (again) these are all personal choices no right or wrong implied. If you need to change a form field or add a field in a form - you have to update the View, update the validation rule in the Controller, and update the fields going to the database in the Model. Thats three different places to build out or do changes. If you make a mistake in your view file maybe the form does not render correctly. If you make a mistake in your controller it can bring everything down. So any changes in the controller are more "costly" to your application.

Versus if you put the validation in the model now you just have two places to do changes. In other words a 'thin' controller handles generalities - not details - so it does not have to change very often.

So we have gone from three to two places. Can we refactor to just one place for our build and future changes? Wouldn't that make it much faster and easier to build and update forms? Yes, the next step is preassembling the form elements (using form helper) into an array that goes to the view. Then almost all the changes are constrained to just the model (or library if you prefer). The View at that point becomes "just a view" with absolutely no responsibilities. I'm just starting to experiment with this and at least so far its amazing in how much easier and faster it is to build out large complex forms and their validation.
Reply


Messages In This Thread
Form Validation Default - by edoramedia - 05-22-2016, 12:32 AM
RE: Form Validation Default - by skunkbad - 05-22-2016, 12:40 AM
RE: Form Validation Default - by cartalot - 05-22-2016, 12:06 PM
RE: Form Validation Default - by albertleao - 05-22-2016, 05:23 PM
RE: Form Validation Default - by cartalot - 05-26-2016, 09:49 AM
RE: Form Validation Default - by albertleao - 05-26-2016, 04:29 PM
RE: Form Validation Default - by skunkbad - 05-26-2016, 10:48 AM
RE: Form Validation Default - by mwhitney - 05-26-2016, 02:14 PM
RE: Form Validation Default - by PaulD - 05-26-2016, 09:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB