HTML::FillInForm rocks hard, but it neither can accept or return HTML::Tree instances, even though it works with them internally.

Therefore, those of us who operate on HTML as trees (e.g. HTML::Seamstress) have to do all the following to leverage FillinForm:

  1. convert our HTML to a string
  2. pass it fillinform
  3. get back the result and turn it back into a tree to continue processing

Now there is a fillinform method in HTML::Element::Library and here is how it's used:

first the html "template"

<html> <head> </head> <body> <form> <input type="text" id="age" name="age" value="balbalh" /> <input type="text" id="email" name="email" /> <input type="text" id="zipcode" name="zipcode" /> </form> </body> </html>

our Perl program

my %form = ( age => 77, email => 'ben@perlmon.com', zipcode => '29063-2134' ); use form_example; my $tree = form_example->new; # calls my $html = $tree->fillinform(\%form) ; warn $html;

and the html form is filled in ...

<form> <input value="77" name="age" type="text" id="age" /> <input value="ben@perlmon.com" name="email" type="text" id="email" /> <input value="29063-2134" name="zipcode" type="text" id="zipcode" /> </form>

Now the Perl class to treeify our HTML

[tbrannon@devel fillinform]$ spkg.pl --base_pkg=HTMLBase form_example. +html comp_root........ /home/tbrannon/prg/html-element-replacer/HTML-Elemen +t-Replacer/ex/tables/ html_file_path... /home/tbrannon/prg/html-seamstress/samples/fillinfor +m/ html_file........ form_example.html html_file sans... form_example substr outside of string at /usr/bin/spkg.pl line 195. WARNING: the comp_root and html_file_path are not equal for the extent + of comp_root... This may lead to incorrect calculations at /usr/bin/spkg.pl line 197.

DONE!

have a nice day!

In reply to tree-based HTML::FillInForm with HTML::Seamstress by metaperl

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.