Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

cwest (1514)

cwest
  (email not shown publicly)
http://caseywest.com/
AOL IM: caseyrwest (Add Buddy, Send Message)

Perl geek.

Journal of cwest (1514)

Thursday August 07, 2003
11:23 AM

Building a Form Generator from Scratch

[ #13974 ]

If I were to build one from scratch today, here's how I'd do it. I'm interested in thoughts.

First and foremost, all the output I would generate by default would have to pass XHTML strict and government guildlines for accessibility.

Second, each form element would be an object, with most object inheriting from the generic "Input" object. This would allow for the greatest flexibility.

Form validation could be optional, but I wouldn't supply any defaults for you, with the possible exception of required fields.

When you build a new form, it would create a new form object. This could be passed into your favorite templating engine and you could create the form yourself by selecting the part you want and iterating over the created form elements.

If you don't want to use your own, you could call a method for the form to render itself. At this point, there should be a way to override default class attribute names on all the HTML elements created. And each element would know how to build itself.

When it comes time to get information out of the form, you could first call the validate method. If that passes, you could use the form object to retrieve the values for each of the form elements. If it does not pass, you could choose to render the form, indicating that a fill-in attempt has been made but failed (or use your own templating system to do this).

I don't think my form generator should automatically use CGI or Apache::Request to get parameters and do validation or sticky form behaviour, but I may be wrong.

As for JavaScript error handling, maybe, maybe not.

As for multi-page forms, it would be nice to handle this automatically, but it's probably not a priority (for me), but I may be wrong.

I think that's about all I can think of.

Posted from caseywest.com, comment here.

New comment creation has been disabled on this discussion.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login
Loading... please wait.