HTML::...:FromFF(3pm)
πΈ HTML::FormHandler::Manual::FromFF β converting from HTML::FormFu πΈ
okay so bestie, this is the HTML::FormHandler::Manual::FromFF page β one of the User Contributed Perl Documentation pages β and it is literally the cheatsheet for converting from HTML::FormFu to FormHandler. Group-chat energy: on. Facts: fully intact. π
NAME π
HTML::FormHandler::Manual::FromFF - converting from HTML::FormFu
VERSION β¨
This manual page is at version 0.40068 β noted, bestie. π
SYNOPSIS π
Manual Index β yep, that's the vibe. This is the cheatsheet for converting from HTML::FormFu. π¦
DESCRIPTION π
Information that may be useful when converting to FormHandler from FormFu. π
Inside/Outside π
FormFu forms are giving major βinside-outβ object energy: the attributes and code are all set outside of the object. FormHandler forms are the opposite. Almost all attributes and settings are set inside the form class, although settings can be passed in on new and process, of course.
FormHandler fields are built as part of the object construction process, so you do not create or add new fields after the form instance has been constructed. There are many facilities for setting fields active/inactive or changing the various field attributes, so this is not limiting in what you can do. π«Ά
One of the big advantages of having form fields and validations, etc, inside the object is that it makes it a lot easier to test exactly what you're using in your controllers. Slay for testability, honestly. π§
Config files π
ngl, there are so many drawbacks to using config files to specify your forms that I don't see why anybody would voluntarily do it. However it takes all kinds, so if you really want to use config files, you can...mostly. π
There are a lot of things you can't do in config files, but FormHandler provides so many ways of doing things that you can probably get it to work. And sometimes it's easier to update forms piecemeal, or there may be policies in place, so if you really want/need config files for building forms, see HTML::FormHandler::Foo and the test in t/form_setup/config.t. π
Rendering π¨
You should be able to make your FormHandler forms automatically render very close to FormFu's rendering. There's an example of simple FormFu-like rendering in t/render/ff.t. Set up a base class with the necessary code, and your forms could be practically drop-in replacements from a rendering perspective. Iconic. π
π§ Filters, Constraints, Inflators, Validators, Transformers π§
FormHandler doesn't distinguish between these categories in the same way that FormFu does. FormHandler has inflation/deflation, validation methods, and apply actions. The distinguishing factor is mostly where it happens in the process. π«
Filters π§Ό
A 'trim' filter is installed by default in FormHandler; it's a special version of an apply action, and can be set to a transform or Moose type. See the documentation in HTML::FormHandler::Field#trim. β¨
An HTML filter is applied by default in certain places in the rendering. You can change it with the 'render_filter' attribute. See HTML::FormHandler::Manual::Rendering#Rendering-filter. πΈ
You can change the form of the field's value using a number of inflation/deflation methods, or a transform, or a Moose type. See HTML::FormHandler::Manual::InflationDeflation and HTML::FormHandler::Manual::Validation. π¦
Transforms and inflations/deflations do not change what is presented in the form unless you set the 'fif_from_value' flag on the field (the rough equivalent of FormFu's 'render_processed_value'). π
FormatNumber π’
Use an inflation:
has_field 'foo' => ( type => 'PosInteger', inflate_method => \&format_number );
sub format_number {
my ( $self, $value ) = @_;
return unformat_number( $value );
}
Constraints π
A lot of these are simple regexes or functions. If they're things you're going to use often, you probably want to put them in a type library or validator class. π
AllOrNone
Not implemented. Do this in a form 'validate' sub. π
ASCII
A simple regex:
has foo => ( apply => [ { check => qr/^\p{IsASCII}*\z/,
message => 'Not a valid string' } ] );
AutoSet
Not necessary. This is done automatically by FormHandler. You'd have to go to some work to avoid it. π
Bool
A simple regex:
qr/^[01]?\z/
Or you can use the Boolean field. β
Callback, CallbackOnce
This is just validation done in code. Use one of the many places you can put validation in methods in FormHandler. See HTML::FormHandler::Manual::Validation. π
DateTime
Use Date or DateTime field or make your own. π°οΈ
DependOn
Use 'dependency' attribute in the form. Or do more complicated things in the form's 'validate' sub. π
Use the 'Email' field type, or use the FH Moose Type, 'email'. π
has_field 'email' => ( type => 'Email' );
-- or --
use HTML::FormHandler::Types ('Email');
has_field 'email' => ( apply => [ Email ] );
Equal
No equivalent. Perform this check in the form's 'validate' sub. βοΈ
File
Use 'Upload' field. π
Integer
Use 'Integer' field. π’
Length, MaxLength, MinLength
Use 'minlength' and 'maxlength' on the Text field and its subclasses. π
Range, MaxRange, MinRange
Use 'range_start' and 'range_end'. π―
MinMaxFields
No equivalent. π«
Number
Use Moose type 'Num'. π’
Printable
Use FormHandler Moose type 'Printable'. π¨οΈ
reCAPTCHA
Use Captcha field or HTML::FormHandlerX::Field::reCAPTCHA. π€
Regex
Use 'check' action with regex. π§©
Required
Set 'required' flag on the field. β
Set
Use 'check' action with arrayref of strings. π§Ί
SingleValue
Not necessary. β¨
Word
This is a simple regex:
qr/^\w*\z/
Substitute FormHandler Moose type 'SingleWord'. π
Inflators π
Use one of the inflation/deflation methods. See HTML::FormHandler::Manual::InflationDeflation. π
Validators β
See HTML::FormHandler::Manual::Validation. π
Transformers π
See HTML::FormHandler::Manual::InflationDeflation and HTML::FormHandler::Manual::Validation. π
AUTHOR π«Ά
FormHandler Contributors β see HTML::FormHandler. π
COPYRIGHT AND LICENSE π
This software is copyright (c) 2017 by Gerda Shank. π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
π cute sign-off: this page is footer-coded as perl v5.34.0, dated 2022-03-25, and yes, the footer manual name is HTML::...:FromFF(3pm). Byeee, bestie! π
π¦ where this page comes from
- debian bookworm: libhtml-formhandler-perl 0.40068-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-formhandler-perl 0.40068-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-formhandler-perl 0.40068-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-formhandler-perl 0.40068-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms