...meaning Yet Another HTML Module. I've come up with a module called FormManager.pm that I've been using quite a bit in recent projects. I'd like the opinions of the fine monks around here as to whether it's worth turning into a CPAN module, or if it's the hacked-up, cobbled-together redundant version of something else as is often the case. For me, it's shaved off quite a bit of development time. Here's an example
use FormManager; my $query = new CGI(); my $fm = new FormManager (layout => [new FormManager::Text (name => 'phone_number', heading => 'Enter +your phone number', validate => 'phone'), new FormManager::Select (name => 'likes_ice_cream', heading => 'Do + you like ice cream?', option_list => ['Yes', 'No']), new FormManager::Hidden (name => 'action', value => 'submit_this_f +orm') ], form_submit => 'Submit this form' ); print "Content-Type: text/html\n\n"; # This script can be called in two ways # 1) Initially to get the form # 2) By submitting the form # If this is case 1) if ($query->param ('action') ne 'submit_this_form') { print $fm->getHtml(); } else { # Ensure that the input is valid. If not, re-print the form if (!$fm->processQuery()) { print $fm->getHtml(); } else { print "Your phone number is : " . $fm->getValue ('phone_number')" +. " and you " . ($fm->getValue ('likes_ice_cream') eq 'No' ? "don't l +ike ice cream." : "like ice cream."); } }
There are numerous features this provides over pure CGI.pm.

1) It's easily extensible. For instance, one could create a FormManager::Date component which consists of three select boxes for month/day/year. In your code, you could treat this as a single input.

2) Validation. This module can validate in a number of ways. So you can use the premade options like 'phone', 'integer', etc, or create your own. Select boxes are automatically checked to ensure the value matches one of the options presented. Validation of all form components is done with a single call to processQuery($query).

3) Easy user-friendliness. If someone enters an incorrect value, or leaves out required information, simply call $fm->getHtml() again after validation. FormManager will fill in all of the old values so that the user doesn't have to re-enter an entire form because of one mistake.

Thanks in advance for the perl-wisdom of the ages.
James

In reply to Is there room for YAHTMLM? by jbeninger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.