Apache-PSP
view release on metacpan or search on metacpan
lib/Template/PSP/autoform.psp view on Meta::CPAN
'day' => ['', 01..31],
'month' => ['', 01..12],
'year' => ['', 2001..2010],
);
foreach my $part ('month', 'day', 'year')
{
my $value = $date{$part};
# record the value in the selected hash
my %selected;
$selected{$value} = 'selected';
# get the lookup values
# and determine the sort order
my @lookup_keys;
my @lookup_values;
my $lookup_ref = $lookups{$part};
if (ref($lookup_ref) eq 'ARRAY')
{
@lookup_keys = @$lookup_ref;
@lookup_values = @$lookup_ref;
}
elsif (ref($lookup_ref) eq 'HASH')
{
# sort the values by hash key
@lookup_keys = sort keys %$lookup_ref;
foreach my $k (@lookup_keys)
{
push (@lookup_values, $lookup_ref->{$k});
}
}
else
{
@lookup_keys = ($lookup_ref);
@lookup_values = ($lookup_ref);
}
# display the form field
print qq{<select name="${name}_${part}${diff}">\n};
my $k = scalar(@lookup_keys) - 1;
for my $i (0..$k)
{
my $key = $lookup_keys[$i];
my $value = $lookup_values[$i];
print qq{<option value="$key" $selected{$key}>$value</option>\n};
}
print qq{</select>};
print '/' unless $part eq 'year';
}
}
else
{
my $fname = $name . $diff;
# display a text box with a date javascript
print qq{<nobr><input type="text" name="$fname" size="10" maxlength="10" value="$value" /> };
print qq{<a href="javascript:show_calendar('$form.$fname');" } .
qq{onmouseover="window.status='Date Picker';return true;" } .
qq{onmouseout="window.status='';return true;">};
print qq{<img src="/images/calendar.gif" /></a></nobr>\n};
}
</perl>
</tag>
<tag name="autofilltest" accepts="nothing">
<perl>
my $result =
{
'field' =>
{
'full_nm' => 'Bill Gates',
'quest' => 'stupid',
'color' => ['green', 'orange'],
'explain' => 'I grew up with a silver spoon in my mouth. That\'s why I founded a giant software company.',
'kidding' => 0,
'really_kidding' => 1,
'sign' => 'Aquarius',
'problem' => 'megalomania',
},
'hidden_fields' =>
[
'sign',
'problem',
],
'lookup' =>
{
'color' =>
[
'green',
'blue',
'red',
'orange',
'purple',
],
'yesno' =>
{
'1' => 'Yes',
'0' => 'No',
},
'quest' =>
{
'stupid' => 'Dominate the Universe',
'dumb' => 'Trash the Planet',
'silly' => 'Save the Planet',
'mild' => 'Read a Book',
'good' => 'Write some Perl',
'great' => 'Buy Stuff for Chuck',
},
'array_yesno' =>
[
'1',
'0',
],
},
};
setpvar('autofill_data', $result);
</perl>
( run in 0.596 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )