SlideShare ist ein Scribd-Unternehmen logo
1 von 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]

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Kürzlich hochgeladen (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

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