Web forms are the most dreary damn things to write
by Derek Sivers
- new or existing?
- existing? login.
- login correct? give cookie & move to edit form
- not correct - give prompt to email forgotten password or create new
- new? create.
- username available? create in database - give cookie & move to edit form
- not available? give error until unique ID chosen
- form for basic info: name, address, etc
- if editing past info, pre-fill form fields and make [SUBMIT] button an [EDIT] buttong
- if brand new, form fields are blank, and [SUBMIT] button is a [CREATE] button
- Validate everything submitted, relentlessly
- Give errors where crucial things are wrong : repeat form until correct
- move to part two of their signup-form
UGH!! Anyone found an PHP-based shortcut for this dreariness?!? I can't just cut-n-paste past forms, because each one I've done over the years is just different enough, that it would be harder to copy-and-change than just start anew.
But there's got to be an easier way. This is SO monotonous. I've spent dozens of hours of my life doing these. I don't want to do all this stuff again. So I keep procrastinating.
Those of you who have graduated from this dreariness, please enlighten the rest of us still stuck in it.
I think I just answered my own question: HTML_QuickForm in PHP's PEAR.
If you're storing the database into a database, you could use DB_DataObject for database access, which is an object-relational mapping tool for PHP. It will create classes for each table in your database by pointing just one small shell script to a database configuration file.
I'm about to release Phorms. It's a little framework that can be used to approach PHP HTML forms management in a more relaxed way :) Basically, it uses a simple XML dialect to create the form. Within the XML you can specify a lot of possible "validator" and user filters (aka pre- and post- processor). By the use of a "hidden router", it then handle automagically all the dirty work to validate the form, redisplay the form (with the yet filled-in fields, of course), and the "route" the page flow to the right "action" (sort of a MVC implementation). Home page is on flexer.it and you can read a short tutorial here. The site in Italian, sorry. Code quality is... mmh... beta ? I'm still developing it, but I currently USE it :)