views:

131

answers:

4

UPDATE: It was suggested in the comments that I create a wiki for this. I have done, you can find it here (should you wish to keep tabs on it and/or contribute).

http://vrs.tomelders.com

I've never worked on anything like this before, so I'm completely winging it.


I've never worked on anything like this before, so please

I'm want to work on an open "standard" or "language", or... well, I don't really know what to call it.... to make form validation easier. I'm calling it VRS (Validation Rule Sheets) but at this stage, everything is negotiable.

The idea is to create a sheet of rules, similar to CSS that define how forms should be validated. This will require

  1. A Syntax / Specification
  2. A VRS Parser to convert the VRS into something useable
  3. A VRS Processor to compare the form data against the rules and return a response.
  4. A response format.

The benefits of a system like this would be

  1. A platform/language agnostic way to define form validations.
  2. A cross platform, highly portable way to define form validations.
  3. Easy to read, easy to setup, easy to modify.
  4. Client side and backend integration.

First things first though. What should the syntax / specification look like.

The way I see this working online is that a VRS file could be specified as a hidden field and the application routes the supplied form data through the VRS processor before processing it.

By way of an example, you could validate the content type of the "name" field would look like this

name {
    content-type: alpha;
}

content-type could be one of three values: alpha, numeric or alpha-numeric.

Hopefully that makes sense. I've never done anything like this before so I'm eager to get other peoples input. Here's as far as I've gotten

------------------------------------------------------------

content-type: (string) alphanumeric | alpha | numeric

Restricts content to either numeric, text or alphanumeric.

------------------------------------------------------------

is-fatal: BOOL

If the rule fails, is it fatal? This could be really useful
for AJAX responses.

------------------------------------------------------------

allow-null: BOOL

wether a field can be empty or not. Good for required fields
and checkboxes 

------------------------------------------------------------

pattern-match: (string) email | url | regex

match the field against a pattern. 

------------------------------------------------------------

field-match: (string) field_name

compares a field to another field. eg: password confirmation

------------------------------------------------------------

greater-than: INT | FLOAT
less-than: INT | FLOAT
within-range: INT | FLOAT, INT | FLOAT

Pretty self explanatory. With regard to strings however, 
the string length is compared against the params.

------------------------------------------------------------

is-unique: (func) connection(host,user,pass), (func) map(table, field)

Check the value against a field in the database to see if
it's unique.

------------------------------------------------------------

date & time validations

This i'm a bit worried about in terms of terminology. I also
want to include dynamic vars in VRS such as

@now
@today
@thisMonth
@thisYear

------------------------------------------------------------

before: STRING | VAR
after: STRING | VAR

Again, self explanatory. Although I'm unsure what the date/time
format should be. UTC?


------------------------------------------------------------

Elapsed Time:

I'm completely stuck on how to handle conditions like
"years elapsed since date is more than 16"

I don't relish the idea of rules as prolix as

years-elapsed-since-now-are-more-than:18;
years-elapsed-since-now-are-less-than:18;

Finally, I'm debating wether devs should be able to specify the errors/warnings in the VRS or should they do that when handling the response?

So, that's a lot to take in and I hope it's clear. My question(s) I guess are

  1. Good idea / bad idea?
  2. Is this the right kind of syntax?
  3. Are there more elegant ways of naming the rules.
  4. What's missing.

thanks


UPDATE: A few people have stated that this proposed system is a bad idea. If you think so, please provide a scenario in which it wouldn't work. Thinking it's a bad idea is one thing, proving it's a bad idea is another, and I'd like to see proof that it's a bad idea sooner rather than later. If you really think form validation could not be made easier or less tedious, please explain why.

In addition, I'm aware that form validation is not a new issue. However, there is currently no portable, cross platform, cross language solution to address form validation, which is what this proposal is specifically addressing.

+1  A: 

I like the idea of putting the error messages in the VRS too. But they should specific to the rule that failed.

Also, you might consider not developing an entirely new "language" but use something like YAML for which parses already exist.

I see this language as being useful as you could use the same VRS for both client- and server-side validation.

PS: This should be community wiki methinks.

Mark
I mentioned in the comments above: I think errors/warning should be handled by the dev based on the response, simply because that would be translations easier.
gargantaun
As for the community wiki, you're right. There's no actual answer to this question. So consider it done.
gargantaun
also, YAML is a nice suggestion, but there's something about it I don't like the look of it. But perhaps that's because I don't use it. The reason I'm thinking of aligning it with CSS is because I think it would make it more human readable. Although it's early days yet. I will look into YAML more.
gargantaun
@gargantaun: I haven't used YAML either, actually, but there are a lot of these config-file type languages. Could use JSON, INI,.. you might consider putting the error messages in some kind of language file then, but my concern is... well, two-fold. You want your VRS to be plug-and-play don't you? Hook the VRS into your system and it's ready to use, without having to work through another system to set up a bunch of error messages. Secondly, for consistency. You want it to spit out the same error messages if its used in different parts of the system, no? Maybe it doesn't have to be tied into ..
Mark
.. the VRS directly, but.. I think it needs some kind of hook that is easy to tap into so that you could have re-usable error messages too.
Mark
I've created a wiki, which can be found at the top of the question now. Should you wish, I'd really appreciate your thoughts on using YAML in the syntax section. So far it only contains my CSS style proposal.
gargantaun
A: 
  1. I suppose it is a good idea, if you can maintain it yourself.

  2. Remember, your making the syntax. It's up to you (so long as it looks decent).

  3. no, not really. So long as the names are obvious (look like what they are), and aren't too long or confusing, then the're fine.

  4. Perhaps you should note default values for the rules when they aren't specified.

Alexander Rafferty
re point 4. Hmmm, this is a tricky one because of translations. I think in the future, the placeholder attribute will negate the need for this. But for now, perhaps something like 'pattern-mismatch' or 'pattern-match: $patern^, fail||pass'
gargantaun
A: 
  1. Good idea / bad idea?

    Generally, this kind of thing is a bad idea. That's what PHP is for.

    What's wrong with http://www.phpformclass.com/ http://www.x-code.com/vdaemon_web_form_validation.php or other PHP form management tools?

  2. Is this the right kind of syntax?

    No. What's wrong with PHP? It has good syntax for this kind of thing.

  3. Are there more elegant ways of naming the rules.

    Yes. PHP object classes. Numerous Other projects. You're not the first person to validate form input.

  4. What's missing.

    Answering the fundamental question: What's wrong with PHP?

    A list of related projects that already do this and specific reasons why your project is better than all the other ones already out there.

S.Lott
Why the hostility? I know you know there are other languages and other platforms. But forms are forms, and as far as I can tell, the validation issues are the same across all languages and platforms. That's why I'm working on a specification first, and the implementation second.
gargantaun
Nothing hostile in my answer at all. Your perceptions are your own, I can't control your feelings. The point is this. The problem has already been solved by other projects. If you can't show how you improve on those projects, you aren't really doing any *better*, just *different*. There's no value in different. There's great value in better.
S.Lott
I personally *like* the idea of a unified validation format that could easily be parsed by different languages, including PHP, JS, C#, etc. That way you could have some cross-language/project consistency, and as I said in my post, so that you could use the same validation file both server and client-side. I definitely see the benefits of this. Whether or not it'll fly and gain popularity is another story.
Mark
@Mark: Liking the idea has nothing to do with showing how the idea is better than the existing projects that already do this.
S.Lott
@Mark: Also, the Django framework already does all of this. That's not PHP, so it may be irrelevant. But this problem has been solved. It's *likable* -- many people like the idea enough to have solved it. This proposal doesn't state how it's *better*.
S.Lott
it's "better" is you insist on using that ambiguous term, because it's platform agnostic, and therefore portable. It means form validation is no longer an anchor tying a project to a legacy code base. It would mean anyone can implement complex form validation regardless of the language or platform they're used to working on. All you've offered so far are radically different approaches to the same problem, specific to platforms and languages.
gargantaun
@gargantaun: Please **update** the question with additional facts.
S.Lott
@gargantaun: "(i'm working in PHP)" Is this not relevant? If it is not relevant, please remove it from the question. If it is relevant, then why describe "specific to platforms and languages" as a problem? I mentioned a language because the question mentioned a language. I never mentioned a platform. Nor did the question.
S.Lott
Again with the hostility. I mentioned PHP because I'm a php developer. If I were to create the first working implementation of this, it would be in PHP. But yeah, ok, I'll remove it from the question. Also, what additional facts would you like?
gargantaun
@gargantaun: Again with projecting your emotional response onto my words. I'm sorry you feel this is hostile. Your emotional response is your problem. I'm trying to explain that your proposal doesn't explain how it improves on any of the existing technology. Merely adding a comment that says "because it's platform agnostic..." doesn't help anyone reading the question. Please update the question to explain why this proposal is "better" and what standard for "better" you're using. This technology exists and is widely used. Please **sell** your idea.
S.Lott
@S.Lott: I'm not sure why he even needs to sell his idea. If it's a project he's interested in doing, let him do it. He's simply asking for suggestions on how to improve what he has in mind. You've made your position clear ("don't do it"), now how about providing some useful feedback? W/ regards to Django doing all of this... how does Django do client-side validation? I've found Django to be seriously lacking in the validation department.
Mark
Also, I wouldn't "like" the idea if it didn't have some benefits over existing frameworks. And I have used many different frameworks before. The VRS language itself isn't enough on it's own to make this fly, but if it had plugins for various languages/frameworks I think it could be good.
Mark
@Mark: "have some benefits over existing frameworks" Really? How and what are these? Why aren't they called out? "now how about providing some useful feedback?" I'm trying to. I suggested that the ways in which it is "better" need to be clarified. I suggested "selling" it -- describing why it's better; some folks describe features and *benefits* as part of a sales pitch. I can't provide anything more useful except to insist on what everyone wants: **details**, **benefits**, **reaons why**.
S.Lott
@S.Lott: I think the benefits have been clearly spelled out. It's not tied to a specific framework. It's a portable solution. It's platform agnostic. The value of these benefits is subjective, but are you arguing that there is no way these things would ever be a benefit? I've also worked with several frameworks and found form validation lacking. This idea was born out of a very real frustration.
gargantaun
@gargantaun: "I think the benefits have been clearly spelled out.". It appears you (a) already think that way and (b) don't feel it necessary to **update** the question to provide details for those of us unable to understand how this improves on existing tools. "This idea was born out of a very real frustration". That's not the point. The point is **details**, **benefits**, **reasons why**. You're free to think it's clear. The point is make it clear to the rest of us. The point is to show why it's **better**. But you appear to refuse to clarify the benefits.
S.Lott
This is going nowhere, I'm out. \*Throws up a peace sign and walks out of the room\*
Mark
@Mark: What's your point? I'm not asking you to clarify. It's not your question. Unless, of course, you are also @gargantaun. What does your comment mean? How does it help clarify?
S.Lott
@S.Lott: What?! There was no point. It's not supposed to help clarify. I said I'm done arguing. You aren't listening to our reasons. Agree to disagree.
Mark
@Mark: I'm asking for clarification. "It's not supposed to help clarify." So why post anything? I'm not disagreeing. I'm asking for an **update** to the question to clarify the details, benefits, and reasons why. If you're not going to clarify, then why comment?
S.Lott
A: 

It's a good idea, but it will be difficult or impossible to cover 100% of the scenarios explicitly in the VRS. In my experience (which may not be typical), the source for new and complicated validation rules is inexhaustible. Examples:

  • Morbidly complex dependencies - If the selected policy is X and its duration is less than Y months and the deductible is between P and Q, then the underwriter can adjust the base premium a maximum of Z%.
  • Validations on aggregates that are difficult to pre-compute - Prevent a trader from executing a trade on a particular equity if doing so will bring our total exposure in that equity's industry over X.
  • Validations based on external data - Has a customer ordered the same supply-limited item on a sister site? Is your address valid? Can I ship there?
  • Deferred/priority execution for expensive validations - Fetching external data can be expensive. Don't even run the validation if a more trivial validation fails.

If you add rules like these to your VRS, you'll eventually end up with a general purpose programming language (which is, I believe, what S.Lott was getting crabby about). Instead, maybe offer a custom validation type. If a validation is custom, the developer provides a server-side and client-side(if appropriate) validation routine and your VRS framework calls them when appropriate.

Corbin March
These are valid points, although I don't think these things come under the remit of form validation, but instead are application/business logic issues. The idea behind form validation, at least as I understand it, is to make sure the data that get's handed to the part of an application that evaluates said data is of the right type. Once that's established, it's up to the application to decide what to do with that input data.
gargantaun
@gargantaun - Agreed that my examples go beyond standard form validation. Your users don't know the difference, however. App logic and simple data type errs are often emphasized/displayed in the same way (highlighted field, summary of err messages...). Worse, the difference is not always obvious to developers. For example, is a field comparison app logic or form validation since it validates more than data type and spans more than one field? It shouldn't be a problem if you're clear where VRS's responsibilities start and stop. Best of luck in your endeavor.
Corbin March