Mojolicious-Plugin-FormFields

 view release on metacpan or  search on metacpan

out.html  view on Meta::CPAN

<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-&#62;plugin(&#39;FormFields&#39;);

  # In your controller
  sub edit
  {
      my $self = shift;
      my $user = $self-&#62;users-&#62;find($self-&#62;param(&#39;id&#39;));
      $self-&#62;stash(user =&#62; $user);
  }

  sub update
  {
      my $self = shift;
      $self-&#62;field(&#39;user.name&#39;)-&#62;is_required;
      $self-&#62;field(&#39;user.password&#39;)-&#62;is_required-&#62;is_equal(&#39;user.confirm_password&#39;);

      if($self-&#62;valid) {
          $self-&#62;users-&#62;update($self-&#62;param(&#39;user&#39;));
          $self-&#62;redirect_to(&#39;/profile&#39;);
          return;
      }
  }

  # In your view
  field(&#39;user.name&#39;)-&#62;text
  field(&#39;user.name&#39;)-&#62;error unless field(&#39;user.name&#39;)-&#62;valid

  field(&#39;user.password&#39;)-&#62;password
  field(&#39;user.age&#39;)-&#62;select([10,20,30])
  field(&#39;user.password&#39;)-&#62;password
  field(&#39;user.taste&#39;)-&#62;radio(&#39;me_gusta&#39;)
  field(&#39;user.taste&#39;)-&#62;radio(&#39;estoy_harto_de&#39;)
  field(&#39;user.orders.0.id&#39;)-&#62;hidden

  # Fields for a collection
  my $kinfolk = field(&#39;user.kinfolk&#39;);
  for my $person (@$kinfolk) {
    $person-&#62;hidden(&#39;id&#39;)
    $person-&#62;text(&#39;name&#39;)
  }

  # Or, scope it to the &#39;user&#39; param
  my $user = fields(&#39;user&#39;)
  $user-&#62;hidden(&#39;id&#39;)
  $user-&#62;text(&#39;name&#39;)
  $user-&#62;error(&#39;name&#39;) unless $user-&#62;valid(&#39;name&#39;)
  $user-&#62;label(&#39;admin&#39;)
  $user-&#62;checkbox(&#39;admin&#39;)
  $user-&#62;password(&#39;password&#39;)
  $user-&#62;select(&#39;age&#39;, [ [X =&#62; 10], [Dub =&#62; 20] ])
  $user-&#62;file(&#39;avatar&#39;)
  $user-&#62;textarea(&#39;bio&#39;, size =&#62; &#39;10x50&#39;)

  my $kinfolk = $user-&#62;fields(&#39;kinfolk&#39;)
  for my $person (@$kinfolk) {
    $person-&#62;text(&#39;name&#39;)
    # ...
  }</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 )