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