[Html-widget] Creating separate fieldsets in a form

Maurice Height mauriceh at bigpond.net.au
Sat Aug 26 05:37:32 CEST 2006

I am new to HTML::Widget and thought as a learning exercise
I would try to replicate the Un-Styled Form at

However I cannot get it to work because the first fieldset, 'Name',
is deleted or overwritten.

Also I have not been able to get the 'RadioGroup' code in the 'Payment
fieldset to work (see comment in my code).
My program and the output I get at the end of it is:

# ManInBlue_Ex.pl
# Application of HTML::Widget to produce a form similar to the
# 'Un-styled Form' at http://www.themaninblue.com/experiment/InForm/

use strict;
use warnings;
use HTML::Widget;
use FindBin;
use IO::All;

#___________________________________ CONFIGURE

# Create temp file path from name of this script
my $ofile_temp = "$FindBin::Bin/$FindBin::Script";
$ofile_temp    =~ s/\.pl$/\.tmp/;


# Create a form containing elements enclosed in 3 separate fieldsets:
# 'Name', 'Address' and 'Payment Details'
my $w1 =

# Add elements to fieldset 'Name'
my $title1 = $w1->element('Select', 'title1');
$title1->options( mr => 'Mr', mrs => 'Mrs', ms => 'Ms', dr => 'Dr',
                  honorable => 'Honorable' );
my $fname = $w1->element('Textfield', 'fname')->label('First
my $lname = $w1->element('Textfield', 'lname')->label('Last

# Add form elements to fieldset 'Address'
my $w2 = HTML::Widget->new('B');
my $street   = $w2->element('Textfield',
my $state    = $w2->element('Textfield', 'state')->label('State')->size(10);
my $postcode = $w2->element('Textfield',
my $country  = $w2->element('Textfield',

# Add form elements to fieldset 'Payment Details'
my $w3 = HTML::Widget->new('C');
$w3->legend('Payment Details');


my $ccard = $w3->element('RadioGroup', 'ccard',
                         ['Amex', 'Master', ' Visa', 'Magic']);
$ccard->label('Credit Card');
# ERROR: when process() is called, HTML::Widget reports that
#        'labels' array ref is undefined
$ccard->labels(['American Express', 'Mastercard', 'Visa', 'Magic']);


my $card_no = $w3->element('Textfield', 'card_no')
                 ->label('Card Number')->size(16);
my $ex_date = $w3->element('Textfield', 'ex_date')
                 ->label('Expiry Date')->size(8);

# Add form buttons
$w3->element('Submit', 'ok' )->value('OK');
$w3->element('Submit', 'cancel' )->value('CANCEL');

$w1->embed($w2, $w3);    # OVERWRITES 'Name' elements

# Create the form code
my $result  = $w1->process;
my $xml_out = $result->as_xml();

# Write output to a temp file
$xml_out > io($ofile_temp);
# Pretty print the temp file using XML::Twig utility program 'xml_pp'
my $cmd    = qq[perl c:\\perl\\bin\\xml_pp $ofile_temp];
my $output = `$cmd`;
print $output;
unlink($ofile_temp) or die;


<form action="/" id="A" method="post">
  <fieldset id="A_B">
    <legend id="A_B_legend">Address</legend>
    <label for="A_B_street" id="A_B_street_label">Street<input
class="textfield" id="A_B_street" name="street" size="15"
    <label for="A_B_state" id="A_B_state_label">State<input
class="textfield" id="A_B_state" name="state" size="10"
    <label for="A_B_postcode" id="A_B_postcode_label">Postcode<input
class="textfield" id="A_B_postcode" name="postcode" size="4"
    <label for="A_B_country" id="A_B_country_label">Country<input
class="textfield" id="A_B_country" name="country" size="15"
  <fieldset id="A_C">
    <legend id="A_C_legend">Payment Details</legend>
    <label for="A_C_card_no" id="A_C_card_no_label">Card Number<input
class="textfield" id="A_C_card_no" name="card_no" size="16"
    <label for="A_C_ex_date" id="A_C_ex_date_label">Expiry Date<input
class="textfield" id="A_C_ex_date" name="ex_date" size="8"
    <input class="submit" id="A_C_ok" name="ok" type="submit" value="OK"/>
    <input class="submit" id="A_C_cancel" name="cancel" type="submit"

Thanks for your time

More information about the Html-widget mailing list