fREWdiculous!
8 Jul
This is just a rant.
I am so sick of validating forms. I do all that I can to make it easy and whatnot, but it still comes back to spite me! Here are two examples of things that are dumb:
So html checkboxes are SO DUMB. If they are checked, the value is set to ‘on.’ That’s annoying alone, but if the checkbox is not set it doesn’t even get submitted! Anyway, that’s pretty annoying. I made a little utility function that lets me just do something like this:
1 |
That works ok I guess. It just feels ghetto.
This is less about forms and more just about how suck I am of this stupid stuff. So let’s say you have some numbers fields in your db. If a person wants to leave the number blank, it gets submitted as ”. Unfortunately that is not a valid number. So you have to convert the ” to undef to get it to store into the database as a NULL. That’s annoying right? No?
Blah. I’m done.
3 Responses for "Form Validation Sucks."
In FormHandler this checkbox issue is handled by a special attribute “input_without_param”. But I don’t understand your concern about ” =! NULL – i the case of non string fields the convention that ” is converted to NULLs works OK – the problem is with string fields – where ” is a valid value.
Have you looked at HTML::FormFu, or Rose::HTML::Form? Both of these provide abstractions that (generally) allow you not to have to worry so much about that level of nitty gritty.
But yeah, generally writing validation sucks, which is why there are so many forms out there on the tubes with bad validation leading to bad user experiences.
No, not annoying. `NULL` means “unknown”. The value submitted isn’t unknown, it was intentionally left blank. I understand that you can’t store a blank value in a numeric column, so one usually decides to either interpret a `NULL` as either “unknown” or “known but blank,” or to assign a default value when it’s known but blank, such as 0. Either way, you *should* have to think about it and make the decision.
Also, HTML forms don’t have “numeric” fields, just text. And of course, a text field that’s known but blank is ”. So you are using a text field for an inherently numeric value and annoyed when you get a text value back. Don’t users also send “foo”?
So the best thing to do is to use a field type where you don’t have to do any validation, such as a select list with all possible (legal) values.
—Theory
Leave a reply