Hello Monks!

As a result of a recent node Populating options in html select I decided to start working on module that would beside filling form fields like existing modules do (such as HTML::FillInForm) also "fill" <select> </select> with possible options.

At this point it's pretty much just a concept and I'm "playing" around by sub classing HTML::Parser as I have no previous experience with any kind of parsing (excluding basic regexps).

At first I thought to subclass the HTML::FillInForm and add just an option to do what I want. But after looking at it's code, I realised that most work is done in one method (fill) so ... I'll just do it from scratch.

I was thinking to make it very simple to be used:

use HTML::FormFill; print HTML::FormFill->fill(html => $html, fields => $hashref, target => 'form_name', selects => {select1 => $AoH_ref, select2 => $Aoh_ref});
Of course, $AoH_ref's will most likely come from DB or something like that. Or to provide easy DBI integration, it could accept output of fetchall_arrayref() ? Fields $hashref could come from CGI's Vars method, DBI's fetchrow_hashref() ... or whatever. Html could be a string or reference to string ...etc.

Any ideas and suggestions are welcome.


Have you tried freelancing? Check out Scriptlance - I work there.

Edit: g0n - Moved from SoPW to Meditations

  • Comment on RFC: HTML::FormFill - but this one should prefill options in selects.
  • Download Code

Replies are listed 'Best First'.
Re: RFC: HTML::FormFill - but this one should prefill options in selects.
by castaway (Parson) on Oct 11, 2005 at 11:25 UTC
    Having read this, and the other node you pointed to, I'm still not quite sure what you're doing. It sounds like you're trying to produce HTML using HTML::Template, yet here you mention HTML::Parser? I dont think writing the HTML out as a Template, and then reparsing it with a Parser to add extra bits is a very good idea.

    So it sounds like you need to make something that works together with HTML::Template, or switch to Template Toolkit?

    C.

Re: RFC: HTML::FormFill - but this one should prefill options in selects.
by fireartist (Chaplain) on Nov 04, 2005 at 12:24 UTC

    Is this of any interest? HTML::Menu::Select

    Use the menu() subroutine if you want to have a template like this:

    <form> <TMPL_VAR select_menu> <input type="submit"> </form>

    Use the options() subroutine if you want to have a template like this:

    <form> <select> <TMPL_VAR select_menu> </select> <input type="submit"> </form>

    You could use it something like this:

    use CGI 'header'; use HTML::Template; use HTML::Menu::Select 'menu'; my $tmpl = HTML::Template->new( ... ); my $select = menu( name => 'response', values => ['yes', 'no'], default => 'yes',] onChange => 'alert(this.value);', ); $tmpl->param( select_menu => $select ); print header(); print $tmpl->output;

    See the docs for more info. The arguments are mostly compatable with CGI.pm's popup_menu routine (though I've just realised I haven't yet documented how they differ (todo!).

    I've also upgraded HTML::Menu::DateTime to use this, so it can optionally generate the HTML rather than data structures.
    Still on the to-do list though, is JS validation