Welcome Guest, Not a member yet? Register   Sign In
Poll: Do we need new solution for Form filtering and validation?
You do not have permission to vote in this poll.
Yes
53.33%
16 53.33%
No
36.67%
11 36.67%
maybe
10.00%
3 10.00%
Total 30 vote(s) 100%
* You voted for this item. [Show Results]

Input filtering and Form validation
#17

Might as well throw my hat into the mix.
The way I view it (and currently do it) is that the model is "incharge" of what the model data should look like and therefore validate it.
You can't add a column to a table for example without getting the mode involved anyway.

As a simple example let's say you have a column which you set to a max length of 32 characters in your database table. The model knows this and therefore when you try to enter 33 characters it fails and says it's to long. You then realize that 64 characters would have been better. Just by changing the code in the model (ie max length from 32 to max length 64) nothing else needs to change (ok maybe a html element attribute in this example but a non PHP dev could do that). The controller say's "hey model is this posted data I got any good?" On fail "Hey model give me a array of the errors to show the user why you didn't like it?" On Pass "Ok can you please save it and let me know if you where able to so I can tell the user?"

The rules are in a array as part of the model
Then I have a mapping like 'insert' & 'update' (also part of the model) which get's the needed rules and run's the validation (and filters - I extended it).

Something like:
$success = $this->validation->validate($the_data,'insert');
$success = $this->validation->validate($the_data,'insert_from_shorter_form');

I always treated the "model" like it was in charge of the data even if it's a file, database table(s), csv file, sftp feed from the moon, etc...

This leaves my controller pretty slim and let's a data "guy" do his thing to make sure the data I am giving him is up to HIS standards.

All that said I think CI should treat the validation library more like it's own thing and not directly attached to form/controllers (They have made changes to reflect this in  recent versions already).

Like somebody else said the library and it's rules work great as they are. I only feel we need to extend it.

I try to think of the Model as 1 Guy, Controller another, and finally View's as a 3rd and none of them like to talk (or talk as little as possible). Of course in real life i'm usually all 3.

DMyers
Reply


Messages In This Thread
Input filtering and Form validation - by sv3tli0 - 04-06-2015, 10:08 PM
RE: Input filtering and Form validation - by dmyers - 04-09-2015, 03:30 PM
RE: Input filtering and Form validation - by cjj - 04-09-2015, 09:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB