Welcome Guest, Not a member yet? Register   Sign In
Form Validation on extended MY_Model
#1

I know that everyone mentions form validation needs to be done on the "model" side.
However I am having trouble wrapping my head around best practice for the following scenario:

I have a MY_Model that has the basic CRUD setup.

Let's say I now have a "user" table where I extend the MY_Model

In "insert" if I want to "insert" through backend I may need to put a lot more items (more "required" items); however if someone "insert"s their details in the register page of the website the form validations may completely be different. I may have "required" fields in backend that are not "required" in registration.

How do I handle something like this dynamically?
Reply
#2

(This post was last modified: 05-24-2016, 12:43 PM by cartalot.)

there is nothing wrong with having more then one form validation method in different places if thats the clearest way to do it. if you have one form for a backend admin, and a very different form for a front end user - keep them separate if thats what makes the most sense for your application flow. saving code should never be at the expense of making your application more difficult to maintain. otherwise if you have one set of form fields and validation that they both share - then you could call that one for both, and call a separate validation method that has the extra fields. there is no problem with calling two validation methods it will work just the same.

one of the ideas with having the form validation in a model - is then you can create the array that goes to your database method in the same place. then you have easy access to the form field names that were used. and when/if form fields get added or changed, you can just go to the model to make those changes, instead of also having to do it in a controller.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB