HTML::FormHandler Bryan Beeley Reach Systems www.reachsystems.com
Quick Moose Review Overview Functional Examples Real World Examples Limitations
Quick Moose Review Object Framework Simple Attribute/Accessor Creation Method Modifiers
Object Framework   package MooseOb; use Moose; ... no Moose; package DerivedOb; use Moose; extends 'MooseOb'; ... no Moose; my $ob = DerivedOb->new; Moose
Moose Simple Attribute/Accessor Creation has 'attribute' => ( # Properties is => 'rw',  # Attribute is read/write isa => 'Str', # Indicate a type ); … $obj->attribute('value'); … $val = $obj->attribute();
Moose Method Modifiers package Base; use Moose; sub method { print ā€œinside\nā€; } package Derived; use Moose; extends 'Base'; before 'method' => sub { print ā€œbefore\nā€; }; around 'method' => sub { my $orig = shift; my $self = shift; print ā€œaround\nā€; $self->$orig(@_); # prints inside print ā€œaround\nā€; }; after 'method' => sub { print ā€œafter\nā€; };
HTML::FormHandler Overview HFH and MVC Forms Simple Example Object Creation Parameter Processing Validation Failed Validation Form Rendering Updating the Data Model Repeatable Fields
Model View Controller Form? HFH and MVC
Forms Fields Type
Name
Value Initial
Input
Validated
Forms – Top level object Fields – Objects within a form Type – The class of the field object
Name – An attribute of the field object
Value – Attributes of the field object Initial – Separate Attribute
Input – Separate Attribute (associted with a result object)
Validated – Separate Attribute
package Form; use HTML::FormHandler::Moose; extends 'HTML::FormHandler'; has_field 'column_name' => ( type => 'Text' ); has_field 'submit' => ( type => 'Submit' ); no HTML::FormHandler::Moose; … my $form = Form->new( item => $object ); $form->process( $params ); if ($form->validated) { # Form submitted successfully } else { $output = $form->render; }
package Form; use HTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; use namespace::autoclean; has_field 'column_name' => ( type => 'Text' ); has_field 'submit' => ( type => 'Submit' ); __PACKAGE__->make_immutable; … my $form = Form->new( item => $dbic_row_ob ); $form->process( $c->req->parameters ); if ($form->validated) { # Redirect or something } else { my $output = $form->render; $c->stash->{template} = \$output; }
Object Creation No attributes and no model required my $form = Form->new; Attributes and row object my $form = Form->new( attr => 'val',
item => $row_ob ); Dynamic form my $form = HTML::FormHandler->new( field_list => [ text => { type => 'Text' },
number => { type => 'Integer' }, ], );

HTML::FormHandler

  • 1.
    HTML::FormHandler Bryan BeeleyReach Systems www.reachsystems.com
  • 2.
    Quick Moose ReviewOverview Functional Examples Real World Examples Limitations
  • 3.
    Quick Moose ReviewObject Framework Simple Attribute/Accessor Creation Method Modifiers
  • 4.
    Object Framework package MooseOb; use Moose; ... no Moose; package DerivedOb; use Moose; extends 'MooseOb'; ... no Moose; my $ob = DerivedOb->new; Moose
  • 5.
    Moose Simple Attribute/AccessorCreation has 'attribute' => ( # Properties is => 'rw', # Attribute is read/write isa => 'Str', # Indicate a type ); … $obj->attribute('value'); … $val = $obj->attribute();
  • 6.
    Moose Method Modifierspackage Base; use Moose; sub method { print ā€œinside\nā€; } package Derived; use Moose; extends 'Base'; before 'method' => sub { print ā€œbefore\nā€; }; around 'method' => sub { my $orig = shift; my $self = shift; print ā€œaround\nā€; $self->$orig(@_); # prints inside print ā€œaround\nā€; }; after 'method' => sub { print ā€œafter\nā€; };
  • 7.
    HTML::FormHandler Overview HFHand MVC Forms Simple Example Object Creation Parameter Processing Validation Failed Validation Form Rendering Updating the Data Model Repeatable Fields
  • 8.
    Model View ControllerForm? HFH and MVC
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    Forms – Toplevel object Fields – Objects within a form Type – The class of the field object
  • 15.
    Name – Anattribute of the field object
  • 16.
    Value – Attributesof the field object Initial – Separate Attribute
  • 17.
    Input – SeparateAttribute (associted with a result object)
  • 18.
  • 19.
    package Form; useHTML::FormHandler::Moose; extends 'HTML::FormHandler'; has_field 'column_name' => ( type => 'Text' ); has_field 'submit' => ( type => 'Submit' ); no HTML::FormHandler::Moose; … my $form = Form->new( item => $object ); $form->process( $params ); if ($form->validated) { # Form submitted successfully } else { $output = $form->render; }
  • 20.
    package Form; useHTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; use namespace::autoclean; has_field 'column_name' => ( type => 'Text' ); has_field 'submit' => ( type => 'Submit' ); __PACKAGE__->make_immutable; … my $form = Form->new( item => $dbic_row_ob ); $form->process( $c->req->parameters ); if ($form->validated) { # Redirect or something } else { my $output = $form->render; $c->stash->{template} = \$output; }
  • 21.
    Object Creation Noattributes and no model required my $form = Form->new; Attributes and row object my $form = Form->new( attr => 'val',
  • 22.
    item => $row_ob); Dynamic form my $form = HTML::FormHandler->new( field_list => [ text => { type => 'Text' },
  • 23.
    number => {type => 'Integer' }, ], );