| 1 |
package HTML::FormHandler::Manual::FromFF; |
| 2 |
# ABSTRACT: converting from HTML::FormFu |
| 3 |
|
| 4 |
__END__ |
| 5 |
|
| 6 |
=pod |
| 7 |
|
| 8 |
=encoding UTF-8 |
| 9 |
|
| 10 |
=head1 NAME |
| 11 |
|
| 12 |
HTML::FormHandler::Manual::FromFF - converting from HTML::FormFu |
| 13 |
|
| 14 |
=head1 VERSION |
| 15 |
|
| 16 |
version 0.410002 |
| 17 |
|
| 18 |
=head1 SYNOPSIS |
| 19 |
|
| 20 |
L<Manual Index|HTML::FormHandler::Manual> |
| 21 |
|
| 22 |
Cheatsheet for converting from L<HTML::FormFu>. |
| 23 |
|
| 24 |
=head1 DESCRIPTION |
| 25 |
|
| 26 |
Information that may be useful when converting to FormHandler from |
| 27 |
FormFu. |
| 28 |
|
| 29 |
=head2 Inside/Outside |
| 30 |
|
| 31 |
FormFu forms look to me like "inside-out" objects. The attributes and |
| 32 |
code are all set outside of the object. FormHandler forms are the |
| 33 |
opposite. Almost all attributes and settings are set *inside* the |
| 34 |
form class, although settings can be passed in on 'new' and 'process', |
| 35 |
of course. FormHandler fields are built as part of the object |
| 36 |
construction process, so you do not create or add new fields after |
| 37 |
the form instance has been constructed. There are many facilities |
| 38 |
for setting fields active/inactive or changing the various field |
| 39 |
attributes, so this is not limiting in what you can do. |
| 40 |
|
| 41 |
One of the big advantages of having form fields and validations, etc, |
| 42 |
inside the object is that it makes it a lot easier to test exactly |
| 43 |
what you're using in your controllers. |
| 44 |
|
| 45 |
=head2 Config files |
| 46 |
|
| 47 |
There are so many drawbacks to using config files to specify your |
| 48 |
forms that I don't see why anybody would voluntarily do it. However |
| 49 |
it takes all kinds, so if you really want to use config files, you |
| 50 |
can...mostly. There are a lot of things you can't do in config files, |
| 51 |
but FormHandler provides so many ways of doing things, that you |
| 52 |
can probably get it to work. And sometimes it's easier to update forms |
| 53 |
piecemeal, or there may be policies in place, so if you really want/need |
| 54 |
config files for building forms, see L<HTML::FormHandler::Foo> and the |
| 55 |
test in t/form_setup/config.t. |
| 56 |
|
| 57 |
=head2 Rendering |
| 58 |
|
| 59 |
You should be able to make your FormHandler forms automatically render |
| 60 |
very close to FormFu's rendering. There's an example of simple FormFu-like |
| 61 |
rendering in t/render/ff.t. Set up a base class with the necessary code, |
| 62 |
and your forms could be practically drop-in replacements from a |
| 63 |
rendering perspective. |
| 64 |
|
| 65 |
=head1 Filters, Constraints, Inflators, Validators, Transformers |
| 66 |
|
| 67 |
FormHandler doesn't distinguish between these categories in the same way |
| 68 |
that FormFu does. FormHandler has inflation/deflation, validation |
| 69 |
methods, and apply actions. The distinguishing factor is mostly |
| 70 |
where it happens in the process. |
| 71 |
|
| 72 |
=head2 Filters |
| 73 |
|
| 74 |
A 'trim' filter is installed by default in FormHandler; it's a |
| 75 |
special version of an apply action, and can be set to a transform |
| 76 |
or Moose type. See the documentation in L<HTML::FormHandler::Field#trim>. |
| 77 |
|
| 78 |
An HTML filter is applied by default in certain places in the rendering. |
| 79 |
You can change it with the 'render_filter' attribute. See |
| 80 |
L<HTML::FormHandler::Manual::Rendering#Rendering-filter>. |
| 81 |
|
| 82 |
You can change the form of the field's value using a number of |
| 83 |
inflation/deflation methods, or a transform, or a Moose type. |
| 84 |
See L<HTML::FormHandler::Manual::InflationDeflation> and |
| 85 |
L<HTML::FormHandler::Manual::Validation>. |
| 86 |
|
| 87 |
Transforms and inflations/deflations do not change what is presented in |
| 88 |
the form unless you set the 'fif_from_value' flag on the field (the rough |
| 89 |
equivalent of FormFu's 'render_processed_value'). |
| 90 |
|
| 91 |
=head3 FormatNumber |
| 92 |
|
| 93 |
Use an inflation: |
| 94 |
|
| 95 |
has_field 'foo' => ( type => 'PosInteger', inflate_method => \&format_number ); |
| 96 |
sub format_number { |
| 97 |
my ( $self, $value ) = @_; |
| 98 |
return unformat_number( $value ); |
| 99 |
} |
| 100 |
|
| 101 |
=head2 Constraints |
| 102 |
|
| 103 |
A lot of these are simple regexes or functions. If they're things |
| 104 |
you're going to use often, you probably want to put them in a type |
| 105 |
library or validator class. |
| 106 |
|
| 107 |
=over 4 |
| 108 |
|
| 109 |
=item AllOrNone |
| 110 |
|
| 111 |
Not implemented. Do this in a form 'validate' sub. |
| 112 |
|
| 113 |
=item ASCII |
| 114 |
|
| 115 |
A simple regex: |
| 116 |
|
| 117 |
has foo => ( apply => [ { check => qr/^\p{IsASCII}*\z/, |
| 118 |
message => 'Not a valid string' } ] ); |
| 119 |
|
| 120 |
=item AutoSet |
| 121 |
|
| 122 |
Not necessary. This is done automatically by FormHandler. You'd have |
| 123 |
to go to some work to avoid it. |
| 124 |
|
| 125 |
=item Bool |
| 126 |
|
| 127 |
A simple regex: |
| 128 |
|
| 129 |
qr/^[01]?\z/ |
| 130 |
|
| 131 |
Or you can use the Boolean field. |
| 132 |
|
| 133 |
=item Callback, CallbackOnce |
| 134 |
|
| 135 |
This is just validation done in code. Use one of the many places |
| 136 |
you can put validation in methods in FormHandler. See |
| 137 |
L<HTML::FormHandler::Manual::Validation>. |
| 138 |
|
| 139 |
=item DateTime |
| 140 |
|
| 141 |
Use Date or DateTime field or make your own. |
| 142 |
|
| 143 |
=item DependOn |
| 144 |
|
| 145 |
Use 'dependency' attribute in the form. Or do more complicated |
| 146 |
things in the form's 'validate' sub. |
| 147 |
|
| 148 |
=item Email |
| 149 |
|
| 150 |
Use the 'Email' field type, or use the FH Moose Type, 'email'. |
| 151 |
|
| 152 |
has_field 'email' => ( type => 'Email' ); |
| 153 |
-- or -- |
| 154 |
use HTML::FormHandler::Types ('Email'); |
| 155 |
has_field 'email' => ( apply => [ Email ] ); |
| 156 |
|
| 157 |
=item Equal |
| 158 |
|
| 159 |
No equivalent. Perform this check in the form's 'validate' sub. |
| 160 |
|
| 161 |
=item File |
| 162 |
|
| 163 |
Use 'Upload' field. |
| 164 |
|
| 165 |
=item Integer |
| 166 |
|
| 167 |
Use 'Integer' field. |
| 168 |
|
| 169 |
=item Length, MaxLength, MinLength |
| 170 |
|
| 171 |
Use 'minlength' and 'maxlength' on the Text field and its subclasses. |
| 172 |
|
| 173 |
=item Range, MaxRange, MinRange |
| 174 |
|
| 175 |
Use 'range_start' and 'range_end'. |
| 176 |
|
| 177 |
=item MinMaxFields |
| 178 |
|
| 179 |
No equivalent. |
| 180 |
|
| 181 |
=item Number |
| 182 |
|
| 183 |
Use Moose type 'Num'. |
| 184 |
|
| 185 |
=item Printable |
| 186 |
|
| 187 |
Use FormHandler Moose type 'Printable'. |
| 188 |
|
| 189 |
=item reCAPTCHA |
| 190 |
|
| 191 |
Use Captcha field or L<HTML::FormHandlerX::Field::reCAPTCHA>. |
| 192 |
|
| 193 |
=item Regex |
| 194 |
|
| 195 |
Use 'check' action with regex. |
| 196 |
|
| 197 |
=item Required |
| 198 |
|
| 199 |
Set 'required' flag on the field. |
| 200 |
|
| 201 |
=item Set |
| 202 |
|
| 203 |
Use 'check' action with arrayref of strings. |
| 204 |
|
| 205 |
=item SingleValue |
| 206 |
|
| 207 |
Not necessary. |
| 208 |
|
| 209 |
=item Word |
| 210 |
|
| 211 |
This is a simple regex: |
| 212 |
|
| 213 |
qr/^\w*\z/ |
| 214 |
|
| 215 |
Substitute FormHandler Moose type 'SingleWord'. |
| 216 |
|
| 217 |
=back |
| 218 |
|
| 219 |
=head2 Inflators |
| 220 |
|
| 221 |
Use one of the inflation/deflation methods. See |
| 222 |
L<HTML::FormHandler::Manual::InflationDeflation>. |
| 223 |
|
| 224 |
=head2 Validators |
| 225 |
|
| 226 |
See L<HTML::FormHandler::Manual::Validation>. |
| 227 |
|
| 228 |
=head2 Transformers |
| 229 |
|
| 230 |
See L<HTML::FormHandler::Manual::InflationDeflation> and |
| 231 |
L<HTML::FormHandler::Manual::Validation>. |
| 232 |
|
| 233 |
=head1 AUTHOR |
| 234 |
|
| 235 |
FormHandler Contributors - see HTML::FormHandler |
| 236 |
|
| 237 |
=head1 COPYRIGHT AND LICENSE |
| 238 |
|
| 239 |
This software is copyright (c) 2017 by Gerda Shank. |
| 240 |
|
| 241 |
This is free software; you can redistribute it and/or modify it under |
| 242 |
the same terms as the Perl 5 programming language system itself. |
| 243 |
|
| 244 |
=cut |