SlideShare a Scribd company logo
1 of 23
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”; } package Derived; use Moose; extends 'Base'; before 'method' => sub { print “before”; }; around 'method' => sub { my $orig = shift; my $self = shift; print “around”; $self->$orig(@_); # prints inside print “around”; }; after 'method' => sub { print “after”; };
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 ,[object Object]
Name
Value ,[object Object]
Input
Validated
Forms – Top level object ,[object Object]
Name – An attribute of the field object
Value – Attributes of the field object ,[object Object]
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 ,[object Object]
item => $row_ob ,[object Object],[object Object]
number => { type => 'Integer' }, ,[object Object],[object Object]

More Related Content

What's hot

Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)Chhom Karath
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3Mizanur Rahaman Mizan
 
WordPress-Powered Portfolios
WordPress-Powered PortfoliosWordPress-Powered Portfolios
WordPress-Powered PortfoliosTyler Sticka
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rob
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko Heijnen
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy DemoSalman Memon
 
High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testingpetersergeant
 
WordCamp Raleigh 2015 - So You Want to Build and Release a Plugin
WordCamp Raleigh 2015 - So You Want to Build and Release a PluginWordCamp Raleigh 2015 - So You Want to Build and Release a Plugin
WordCamp Raleigh 2015 - So You Want to Build and Release a Pluginryanduff
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksShawn Rider
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesMarcello Duarte
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party AuthenticationAaron Brazell
 
jQuery - Doing it right
jQuery - Doing it rightjQuery - Doing it right
jQuery - Doing it rightgirish82
 
Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsPierre MARTIN
 

What's hot (20)

Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
WordPress-Powered Portfolios
WordPress-Powered PortfoliosWordPress-Powered Portfolios
WordPress-Powered Portfolios
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
 
Ampersandjs
AmpersandjsAmpersandjs
Ampersandjs
 
High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testing
 
Framework
FrameworkFramework
Framework
 
WordCamp Raleigh 2015 - So You Want to Build and Release a Plugin
WordCamp Raleigh 2015 - So You Want to Build and Release a PluginWordCamp Raleigh 2015 - So You Want to Build and Release a Plugin
WordCamp Raleigh 2015 - So You Want to Build and Release a Plugin
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
 
Count to 10 and Say Yes
Count to 10 and Say YesCount to 10 and Say Yes
Count to 10 and Say Yes
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
 
Php Basic
Php BasicPhp Basic
Php Basic
 
jQuery - Doing it right
jQuery - Doing it rightjQuery - Doing it right
jQuery - Doing it right
 
Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP Behaviors
 

Similar to HTML::FormHandler

Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstartguestfd47e4c7
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Securitymussawir20
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)xSawyer
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Michael Wales
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised contentMichael Peacock
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In PhpHarit Kothari
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 

Similar to HTML::FormHandler (20)

Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstart
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 
Further Php
Further PhpFurther Php
Further Php
 
Views notwithstanding
Views notwithstandingViews notwithstanding
Views notwithstanding
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
PHP
PHP PHP
PHP
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Drupal Form Api
Drupal Form ApiDrupal Form Api
Drupal Form Api
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised content
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

HTML::FormHandler

  • 1. HTML::FormHandler Bryan Beeley Reach Systems www.reachsystems.com
  • 2. Quick Moose Review Overview Functional Examples Real World Examples Limitations
  • 3. Quick Moose Review Object 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/Accessor Creation has 'attribute' => ( # Properties is => 'rw', # Attribute is read/write isa => 'Str', # Indicate a type ); … $obj->attribute('value'); … $val = $obj->attribute();
  • 6. Moose Method Modifiers package Base; use Moose; sub method { print “inside”; } package Derived; use Moose; extends 'Base'; before 'method' => sub { print “before”; }; around 'method' => sub { my $orig = shift; my $self = shift; print “around”; $self->$orig(@_); # prints inside print “around”; }; after 'method' => sub { print “after”; };
  • 7. HTML::FormHandler Overview HFH and MVC Forms Simple Example Object Creation Parameter Processing Validation Failed Validation Form Rendering Updating the Data Model Repeatable Fields
  • 8. Model View Controller Form? HFH and MVC
  • 9.
  • 10. Name
  • 11.
  • 12. Input
  • 14.
  • 15. Name – An attribute of the field object
  • 16.
  • 17. Input – Separate Attribute (associted with a result object)
  • 19. 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; }
  • 20. 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; }
  • 21.
  • 22.
  • 23.
  • 24. $form->process; $form->process( $params ); my $success = $form->process( params => $params, arg => $arg, ); Parses form data out of parameters Saves input data in field objects Validates input data Generates error messages if appropriate Parameter Processing
  • 25. Validation Default has_field 'number' => ( type => 'Integer', required => 1, ); In your form class has_field 'no_spaces' => ( type => 'Text' ); sub validate_no_spaces { my ($self, $field) = @_; $form->add_error('Must not have spaces') if $field->value =~ //; } In your field class sub validate { my $self = shift; ... $self->add_error('My custom message') if $error; }
  • 26. Failed Validation Check the process return value my $success = $form->process; Add an error message $field->add_error('Error message'); Check a form for errors if ($form->has_errors) { … } Check a field for errors if ($field->has_errors) { … } Get form error messages my @error_messages = $form->errors;
  • 27. Form Rendering Render into a scalar using HFH widgets my $output = $form->render; Render in a Template Toolkit template using HFH widgets [% form.render %] Let Template Toolkit do the work [% f = form.field('my_text_field') %] Enter some text: <input type=”text” name=”[% f.html_name %]” value=”[% f.html_filter(f.fif) %]” />
  • 28. Updating the Data Model Use the HFH Model Interface in your form extends 'HTML::FormHandler::Model::DBIC'; Roll your own form update_model method sub update_model { … } Use any object that with accessors matching field names $form->process( item => $object, params => $params );
  • 29. Repeatable Fields has_field 'order_id' => ( type => 'PosInteger' ); has_field 'cart_items' => ( type => 'Repeatable' ); has_field 'cart_items.cost' => ( type => 'Money' ); has_field 'cart_items.name' => ( type => 'Text' ) ; … JavaScript to dynamically add items to the cart … DBIC extension will submit rows into the related table
  • 32. Default rendering is very primitive HFH DBIC model has problems in some cases Repeatable fields forget initial values new and process do the same thing twice Limitations
  • 33. Workarounds and Solutions Override render, or create your own widgets Write your own update_model Patches are welcome Cache form objects