Validation framework
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Validation framework
What exactly should one include?
I've looked into Zend and CodeIgnitor and both seem to support some kind of filter/validate chain.
I need somethign really simple and not something that filters, etc...something with customizable messages...
I've looked into vdameon:
http://www.x-code.com/vdaemon_web_form_validation.php
I couldn't find much in terms of examples or concepts, but admittedly I didn't look hard (apparently I really didn't look hard: http://www.x-code.com/vdaemon/manual/index.htm).
I asked thie here incase it takes on a "discussion" otherwise I suppose it would be best in General if it takes on the purpose of just hilighting existinging solutions.
What are some questions you ask when looking for validation?
Cheers,
Alex
I've looked into Zend and CodeIgnitor and both seem to support some kind of filter/validate chain.
I need somethign really simple and not something that filters, etc...something with customizable messages...
I've looked into vdameon:
http://www.x-code.com/vdaemon_web_form_validation.php
I couldn't find much in terms of examples or concepts, but admittedly I didn't look hard (apparently I really didn't look hard: http://www.x-code.com/vdaemon/manual/index.htm).
I asked thie here incase it takes on a "discussion" otherwise I suppose it would be best in General if it takes on the purpose of just hilighting existinging solutions.
What are some questions you ask when looking for validation?
Cheers,
Alex
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Validation framework
vdameon looks totally hackable. They display raw $_POST and seem to get all the validation rules from custom HTML tags. I I hope they have parallel server side filtering and validation.
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Validation framework
I agree...I like the idea of Zend/CI and their filter chains and grouping primitives togather to validate a single entity...
Although to do that for every input variable...yikes seems a lot of work or clutter not much better than manually checking input...
I suppose you could wrap each into a base type...but then what about error messages being customized for each entity.
If you validate an email...on a account's page how do you validate 2 emails (one primary and one secondary) while still informing the user as to the exact email address which failed?
You did something like this in Skeleton, didn't you? How did you solve these issues?
Although to do that for every input variable...yikes seems a lot of work or clutter not much better than manually checking input...
I suppose you could wrap each into a base type...but then what about error messages being customized for each entity.
If you validate an email...on a account's page how do you validate 2 emails (one primary and one secondary) while still informing the user as to the exact email address which failed?
You did something like this in Skeleton, didn't you? How did you solve these issues?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Validation framework
I think the thing that people don't want to admit is that with forms the hard way is the only good way. So the question is how to make the hard way reasonable.PCSpectra wrote:Although to do that for every input variable...yikes seems a lot of work or clutter not much better than manually checking input...
Ninja did a revamp on the Rules and Filters a month or so ago. He got sick of Zend and was influenced by Django. There is also a Form Model class that combines filter and rule chains. It still needs a layer defining the form in data built over it if anyone wants to volunteer.PCSpectra wrote:You did something like this in Skeleton, didn't you? How did you solve these issues?
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Validation framework
Busted...I think the thing that people don't want to admit is that with forms the hard way is the only good way.
The hard way is "usually" the best way so long as it's not ignorance that leads you to taking the hard way...
Yea I remember him going off about that...Ninja did a revamp on the Rules and Filters a month or so ago. He got sick of Zend and was influenced by Django. There is also a Form Model class that combines filter and rule chains. It still needs a layer defining the form in data built over it if anyone wants to volunteer. But you might need to have done a full harrowing of forms solutions to appreciate it...
By forms solution...what do you mean? Form generation and the whol kitten kaboodle?
I personally dislike the idea of building forms with an API...you must lose much control over the "interface" going this direction, especially without a ton of hacking. While it would be nice because forms have a tendancy to programmatically influenced (show this checkbox for this user but not others kind of deal) I find that interface changes most often.
Ideally I just want a really light weight validation library...not even a framework as it shouldn't promote any best practice or force any kind of design decision...whether I want it done in the controller, model or view, the library should be totally agnostic about that.
Perhaps most important is the fact I need full control over the error messages. Which is what is leading in the direction that if you want it done "right" (according to my own standards) it needs to be done the old fashion way.
Cheers,
Alex
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Validation framework
There are a number of different parts and layers to choose from. There are basic Rules and Filters. There is a Form Model that combines them and runs them against the Request. If you want to optionally generate HTML, there are also separate Form HTML classes that can get the values from a Form Model object. You can combine or use what you want. All can generally be used standalone as well.PCSpectra wrote:By forms solution...what do you mean? Form generation and the whol kitten kaboodle?
I personally dislike the idea of building forms with an API...you must lose much control over the "interface" going this direction, especially without a ton of hacking. While it would be nice because forms have a tendancy to programmatically influenced (show this checkbox for this user but not others kind of deal) I find that interface changes most often.
Ninja (and pytrin before him) added some interesting ways to make fields required or optional to give fine grained control over what gets validated.
They are not tied into anything. They are just a bunch of classes. And since Rules and Filters are atomic objects you can easily add your own custom ones.PCSpectra wrote:Ideally I just want a really light weight validation library...not even a framework as it shouldn't promote any best practice or force any kind of design decision...whether I want it done in the controller, model or view, the library should be totally agnostic about that.
Unlike other systems there are no default error messages. You provide the error message you want to get back on failure. The messages are returned in an array with keys telling you were the error came from (if you want to know). Up to you how you display them It is pretty bare bones like most things in Skeleton.PCSpectra wrote:Perhaps most important is the fact I need full control over the error messages. Which is what is leading in the direction that if you want it done "right" (according to my own standards) it needs to be done the old fashion way.
(#10850)
Re: Validation framework
Never had to update 100 multi-page forms at once, have you? With the zend decorator solution you have pretty much full control over everything you just listed as a concern. What's also great about using a forms API is you can define you forms as classes, and use structural and behavioral design patterns to re-use concepts, and individual form components ( several form fields that make up a larger "logical" widget within the form, for instance 3 dropdowns can be logically thought of as 1 date input.. with a forms API you can make this it's own object that knows how to validate itself )PCSpectra wrote:I personally dislike the idea of building forms with an API...you must lose much control over the "interface" going this direction, especially without a ton of hacking.
You're free to dislike it but with the Zend solution at least you don't really loose a lot of control. The stuff that IS out of your control can be easily extended in 1/1000th the time it would take to rewrite all your forms manually every time they change. With an API you can rewrite the interface hourly instead of monthly
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: Validation framework
I can't really say I'm a fan of forms API's. I like my HTML to look like HTML. A lot of that has to do with the fact that we have a handful of people involved with application development. We create some basic, workable HTML to start out with, but that HTML is going to heavily modified over time by the usability person/graphics designer.
The usability person is not someone who's very skilled in PHP, but they still need the ability to rearrange the form layout, add new content, and generally change how the form looks in the quest to make it as easy for end users as possible. For example, the usability person is the one to decide how to do date entry; whether to do a drop down for month,day,year, or whether to have a text box, or whether to use a javascript date popup.
They are also the one to decide if a form needs be split up into multiple screens. Giving them control of the HTML for the forms is the way to go for us.
The filtering and validation all happens in the Model anyway, so they're pretty free to go to town with the markup.
The usability person is not someone who's very skilled in PHP, but they still need the ability to rearrange the form layout, add new content, and generally change how the form looks in the quest to make it as easy for end users as possible. For example, the usability person is the one to decide how to do date entry; whether to do a drop down for month,day,year, or whether to have a text box, or whether to use a javascript date popup.
They are also the one to decide if a form needs be split up into multiple screens. Giving them control of the HTML for the forms is the way to go for us.
The filtering and validation all happens in the Model anyway, so they're pretty free to go to town with the markup.
- VirtuosiMedia
- Forum Contributor
- Posts: 133
- Joined: Thu Jun 12, 2008 6:16 pm
Re: Validation framework
I have a small framework I'm gradually building. It doesn't have much yet, but I do have the form solution with filtering and validating mostly done if you're interested in looking at it. For the validate class, I stored the errors in two arrays: one for all the error messages for the entire form and one for each field. Each validator also has a default error or an optional error attribute. This allows me to output errors with a little bit of flexibility and would probably solve your primary/secondary email problem.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Validation framework
I am interested to understand the differences. I don't generate the whole form in code. I have looked as things like QuickForm and Zend Form, but must have not understood the benefits. I let a designer deal with the HTML and I just mostly deliver values. I have not noticed that changes take much time, especially because I don't do them -- the designers deal with them as regular old HTML pages. The only time I get involved is when a new field is added, or filtering/validation changed. I am wondering what the difference between the API and non-API versions is in the practical workflow sense.jshpro2 wrote:Never had to update 100 multi-page forms at once, have you? With the zend decorator solution you have pretty much full control over everything you just listed as a concern. What's also great about using a forms API is you can define you forms as classes, and use structural and behavioral design patterns to re-use concepts, and individual form components ( several form fields that make up a larger "logical" widget within the form, for instance 3 dropdowns can be logically thought of as 1 date input.. with a forms API you can make this it's own object that knows how to validate itself )
(#10850)
Re: Validation framework
You could write a builder that parses an HTML DOM and configures the forms API. My argument was just if you have a ton of UI code that is very volatile, a robust forms API becomes essential.
Re: Validation framework
Well for one you can treat your forms like objects, have forms inherit from eachother, use design patterns ( in theory ). In zend you use decorators to generate the HTML, so for instance every field has a label among other various options. If you wanted you could write a decorate that looks up in a database a tooltip for each label, to centralize your tooltips. This is just an example one thing that becomes possible. You can also build custom form elements that are primitive elements combined, like defining a date element that composites 3 dropdowns and uses customized HTML display decorates for instance.arborint wrote: I am wondering what the difference between the API and non-API versions is in the practical workflow sense.
http://framework.zend.com/manual/en/zen ... ators.html
http://framework.zend.com/manual/en/zen ... ators.html
I haven't looked into Skeleton's form libraries, I plan to though. I must say Skeletons MVC implementation is more elegant than Zends.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Validation framework
Ok ... I guess for stuff like tooltips I would probably provide a JSON array of strings to the designer and let them do whatever they want with them. I sort of treat myself as the Model, and the designer as the View. I have been heading more the direction of generating JSON rather than generating HTML and pushing almost all the presentation to the a View where more Presentation Logic is done in Javascript. It is something I have wanted to add to Skeleton.
FYI - Skeleton has much of the same functionality as Zend from what I understand (I don't use it). You can add objects or strings to append/prepend and for the label. It is done differently -- mainly because the HTML generation component is separate from the data container (e.g. the Form Model). So it is more loosely integrated. And it is probably much more bare-bones than any Zend solution. You'd probably be a great person to improve the Skeleton code!
FYI - Skeleton has much of the same functionality as Zend from what I understand (I don't use it). You can add objects or strings to append/prepend and for the label. It is done differently -- mainly because the HTML generation component is separate from the data container (e.g. the Form Model). So it is more loosely integrated. And it is probably much more bare-bones than any Zend solution. You'd probably be a great person to improve the Skeleton code!
(#10850)
Re: Validation framework
From my understanding zend uses view helpers to render the form. The solution has its rough edges I'll admit that. The tooltip thing was just to refute the argument that was made against using APIs. If you have the need to pragmatically manipulate form structure and appearance, you need an API. CSS is great for pure aesthetics, but like I said plain HTML has its pitfalls. Sure you can overcome some of them by using include() within the form HTML definition, but the fact still remains there are certain requirements which call for an API. On a simple project yes it is a matter of preference, but based on your requirements and context, it is not a matter of opinion that a forms API is better, it is fact.arborint wrote:mainly because the HTML generation component is separate from the data container (e.g. the Form Model).
- VirtuosiMedia
- Forum Contributor
- Posts: 133
- Joined: Thu Jun 12, 2008 6:16 pm
Re: Validation framework
jshpro2, how do you generate your HTML? I've been using this simple XML function that I wrote and it's been working well for me, but I'm curious to see how you do it.
Code: Select all
function createTag($tagName, array $attributes = array(), $selfClosing = FALSE){
$tag = "<$tagName";
foreach ($attributes as $attribute=>$value){
$attribute = strtolower($attribute);
if ($attribute != 'innerhtml'){
$tag .= ' '.$attribute.'="'.$value.'"';
} else {
$innerHTML = $value;
}
}
if ($selfClosing){
$tag .= " />";
} else {
$tag .= ">";
if ($innerHTML){
$tag .= $innerHTML;
}
$tag .= "</$tagName>";
}
return $tag;
}