Slash Boxes
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 ]

samtregar (2699)

  (email not shown publicly)

Journal of samtregar (2699)

Monday December 03, 2007
02:57 PM

HTML::FIllInForm patch to mark invalid fields

[ #35037 ]
I've been working on producing yet another form validation system, this time for MasonX::WebApp. I modeled my work on the very nice CGI::Application::Plugin::ValidateRM, with a bit of the Krang::Message system thrown in to help get errors out to the user.

One thing I wanted to do this time that I'd never done before was automate marking invalid form fields. I'd done this in the past using manual template changes, but that's a lot of grunt work.

Instead, my coworker Perrin Harkins suggested we use HTML::FillInForm to do the job. We're already using it to re-fill forms with errors, so why not use it to setup a CSS class on invalid fields too. It turns out HTML::FillInForm has a very similar facility already to disable selected fields, so adding an invalid fields feature was pretty simple.

I've already sent along the patch to the maintainer, but if you want to get it now here it is:


The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Awesome! I've always thought it a kludge that we have to use templates to mark invalid fields when we have the niceness of HTML::FillInForm doing the filling for us. Is this generic enough to do any kind of class setting for fields?
    • Thinking about my comment a little more, perhaps I should clarify. Instead of having the ability to specifically mark fields as invalid, why not be able to mark any fields a certain way. Something like:

      HTML::FillInForm->fill(\$html, $q,
          classify => {
              invalid => [qw(name password)],
              required => [qw(name password birth_date)],

      These are just the first 2 obvious uses I see for this, but I'm sure there are other
      • Sounds potentially useful, although I can't say I have an immediate need for it. I think it would be a pretty easy change to make.


      • I think I'll like this patch as well.

        However, I think the form should be clearly marking which fields are required even before it is reloaded.

        So, a simple "invalid" class perhaps should be enough.

        I know ValidateRM usually puts "missing" or "invalid" on the page, but I had one customer who wanted to just use "Oops!" in all cases. I think that works in most cases, since the page design should already provide the context to explain /why/.

        In a few cases it is imported to provide more detail, like explaining tha
        • However, I think the form should be clearly marking which fields are required even before it is reloaded.

          You're assuming that I don't already run the form through HTML::FillInForm the first time. It's not just good for showing a form to a user for correcting, but for prefilling a form with either default values or something else (in the case of an edit screen).

          You're also assuming that the fields on a form are predefined. We have a CMS that let's users add extra custom fields to different form types and to decide which of those custom fields is required. Having the ability to do this when the form passes thro