in reply to CGI.pm Disillusionment
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: CGI.pm Disillusionment
by Cody Pendant (Prior) on Jun 05, 2003 at 00:46 UTC | |
Well exactly. That's what I wanted. Forms which can report an error/missing field then pump out the field contents which are OK. Is there another solution for this kind of thing? It's easy enough to do field contents but checkboxes, radiobuttons and select lists always require some kludge. if(<param exists that matches the name>){print "selected" } or whatever
Kludges are what I do best, but I'm trying to get away from that...
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer. | [reply] [d/l] |
by cees (Curate) on Jun 05, 2003 at 03:03 UTC | |
Check out HTML::FillInForm for populating form fields without needing to use CGI.pm to generate the HTML. I use it very successfully with CGI::Application, HTML::Template and Data::FormValidator. A typical C::A runmode for me looks like the following:
And the template would have the following fields in it:
CGI::Application keeps my code structured nicely, HTML::Template allows me to separate design from code (including the content of error messages intended for the end-user), Data::FormValidator does most of the input field checking, and HTML::FillInForm gives me sticky form fields. And I usually top it off with Class::DBI for the database interface. This turned out to be a bit longer than I intended, but hopefully someone finds it useful (or someone points out where I can improve things :). Cheers | [reply] [d/l] [select] |
by Cody Pendant (Prior) on Jun 05, 2003 at 03:54 UTC | |
-- Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer. | [reply] |
by perrin (Chancellor) on Jun 05, 2003 at 02:42 UTC | |
| [reply] |
by edoc (Chaplain) on Jun 05, 2003 at 01:40 UTC | |
Well, I dunno about it's kludge-worthiness, but for checkboxes, radio buttons, and selects for a quick form I had to do recently I went with extra template tags in the respective tags then in my script I set the appropriate values to 'selected' or 'checked' so my template looks like:
And after processing:
Of course you're still going to have to process the input and set the appropriate values, but for that I created a config type hash containing the names of the different inputs grouped by type. For each I also specified a human readable label. Then I created a 'required' hash of input fields. The script then checks that any fields in the 'required' hash have been specified and if not, uses their labels to create the error message. Then we go through the field hashes to set appropriate values for 'selected' and 'checked'. cheers, J | [reply] [d/l] [select] |