HTML-FormBuilder
view release on metacpan or search on metacpan
example/app.psgi view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# To test this, run it as:
# plackup --host 127.0.0.1 --port 8080 app.psgi
# On browser, access page via:
# http://127.0.0.1:8080
BEGIN {
unshift @INC, '../lib';
}
use Plack::Request;
use HTML::FormBuilder::Validation;
use HTML::FormBuilder::Select;
sub get_form {
my $form = HTML::FormBuilder::Validation->new(data => {
name => 'openAccForm',
id => 'openAccForm',
class => 'formObject grd-row-padding',
method => 'post',
action => '/test',
});
my $fieldset = $form->add_fieldset({ legend => 'details' });
$fieldset->add_field({
'label' => {
'text' => 'Salutation',
'for' => 'salutation',
},
'input' => HTML::FormBuilder::Select->new(
'id' => 'salutation',
'name' => 'salutation',
'options' => [ { value => '', text => 'Select Salutation' }, { value => 'Mr', text => 'Mr' }, { value => 'Ms', text => 'Ms' }, { value => 'Dr', text => 'Dr' } ],
),
'error' => {
'id' => 'errorsalutation',
'class' => 'errorfield'
},
'validation' => [{
'type' => 'regexp',
'regexp' => '^\w+$',
'err_msg' => 'Please select salutation.',
},
],
});
$fieldset->add_field({
'label' => {
'text' => 'Name',
'for' => 'name',
},
'input' => {
'id' => 'name',
'name' => 'name',
'type' => 'text',
'maxlength' => 30,
},
'error' => {
'id' => 'errorname',
'class' => 'errorfield'
},
'validation' => [{
'type' => 'regexp',
'regexp' => '^.{5}.*$',
'err_msg' => 'Name should be > 5 characters.',
},
{
'type' => 'regexp',
'regexp' => '^[a-zA-Z\s\'.-]+$',
'err_msg' => 'Please use only letters, spaces, hyphens, full-stops or apostrophes.',
},
],
});
$fieldset->add_field({
'label' => {},
'input' => {
'id' => 'submit',
'name' => 'submit',
'type' => 'submit',
'value' => 'Submit',
},
'error' => {
'id' => 'invalidinputfound',
( run in 0.519 second using v1.01-cache-2.11-cpan-140bd7fdf52 )