Mojolicious-Plugin-FormFields
view release on metacpan or search on metacpan
<html><head><title>Mojolicious::Plugin::FormFields</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body class='pod'>
<!--
generated by Pod::Simple::HTML v3.28,
using Pod::Simple::PullParser v3.28,
under Perl v5.018001 at Sat Jun 14 02:51:03 2014 GMT.
If you want to change this HTML document, you probably shouldn't do that
by changing it directly. Instead, see about changing the calling options
to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
then reconverting this document from the Pod source.
When in doubt, email the author of Pod::Simple::HTML for advice.
See 'perldoc Pod::Simple::HTML' for more info.
-->
<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>
<h1><a class='u'
name="NAME"
>NAME</a></h1>
<p>Mojolicious::Plugin::FormFields - Lightweight form builder with validation and filtering</p>
<h1><a class='u'
name="SYNOPSIS"
>SYNOPSIS</a></h1>
<pre> $self->plugin('FormFields');
# In your controller
sub edit
{
my $self = shift;
my $user = $self->users->find($self->param('id'));
$self->stash(user => $user);
}
sub update
{
my $self = shift;
$self->field('user.name')->is_required;
$self->field('user.password')->is_required->is_equal('user.confirm_password');
if($self->valid) {
$self->users->update($self->param('user'));
$self->redirect_to('/profile');
return;
}
}
# In your view
field('user.name')->text
field('user.name')->error unless field('user.name')->valid
field('user.password')->password
field('user.age')->select([10,20,30])
field('user.password')->password
field('user.taste')->radio('me_gusta')
field('user.taste')->radio('estoy_harto_de')
field('user.orders.0.id')->hidden
# Fields for a collection
my $kinfolk = field('user.kinfolk');
for my $person (@$kinfolk) {
$person->hidden('id')
$person->text('name')
}
# Or, scope it to the 'user' param
my $user = fields('user')
$user->hidden('id')
$user->text('name')
$user->error('name') unless $user->valid('name')
$user->label('admin')
$user->checkbox('admin')
$user->password('password')
$user->select('age', [ [X => 10], [Dub => 20] ])
$user->file('avatar')
$user->textarea('bio', size => '10x50')
my $kinfolk = $user->fields('kinfolk')
for my $person (@$kinfolk) {
$person->text('name')
# ...
}</pre>
<h1><a class='u'
name="DESCRIPTION"
>DESCRIPTION</a></h1>
<p><code>Mojolicious::Plugin::FormFields</code> allows you to bind objects and data structures to form fields. It also performs validation and filtering via <a href="http://search.cpan.org/perldoc?Validate%3A%3ATiny" class="podlinkpod"
>Validate::Tiny</a>.</p>
<h1><a class='u'
name="CREATING_FIELDS"
>CREATING FIELDS</a></h1>
<p>Fields can be bound to a hash, an array, something blessed, or any combination of the three. They are created by calling the <code><a href="#field" class="podlinkpod"
( run in 1.552 second using v1.01-cache-2.11-cpan-0d23b851a93 )