Web forms are the most dreary damn things to write

by Derek Sivers

As you can see by my other posts here, I *LOVE* programming. It's really my 2nd favorite thing on earth. But tonight as I had to do yet-another "web signup form" thing, I just found myself HATING the process.

  • 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

  • repeat

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.


2004-08-21 23:25:48
I think I just answered my own question: HTML_QuickForm in PHP's PEAR.

Looks pretty advanced, like it can handle any HTML-form situation I can think of.

2004-08-22 06:50:43
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.

You can then use these classes with DB_DataObject_FormBuilder, which automatically creates a form to fill the table - of course, you can still apply any kind of customization that you might want. What comes out is a HTML_QuickForm object.

FormBuilder will also take care of detecting whether it deals with existing or new data and will use the DataObject to automagically perform the appropriate action on the database.

Sounds complicated? It isn't. It's really just a shell script that you use exactly one time and then about 5-6 lines of code to create a fully functional form... plus any form customization, should that be needed.

Go here:

2004-08-23 11:03:48
Phorms ?
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 :)