1HTML::FormHandler(3) User Contributed Perl Documentation HTML::FormHandler(3)
2
3
4
6 HTML::FormHandler - HTML forms using Moose
7
9 version 0.40068
10
12 See the manual at HTML::FormHandler::Manual.
13
14 use HTML::FormHandler; # or a custom form: use MyApp::Form::User;
15 my $form = HTML::FormHandler->new( .... );
16 $form->process( params => $params );
17 my $rendered_form = $form->render;
18 if( $form->validated ) {
19 # perform validated form actions
20 }
21 else {
22 # perform non-validated actions
23 }
24
25 Or, if you want to use a form 'result' (which contains only the form
26 values and error messages) instead:
27
28 use MyApp::Form; # or a generic form: use HTML::FormHandler;
29 my $form = MyApp::Form->new( .... );
30 my $result = $form->run( params => $params );
31 if( $result->validated ) {
32 # perform validated form actions
33 }
34 else {
35 # perform non-validated actions
36 $result->render;
37 }
38
39 An example of a custom form class:
40
41 package MyApp::Form::User;
42
43 use HTML::FormHandler::Moose;
44 extends 'HTML::FormHandler';
45 use Moose::Util::TypeConstraints;
46
47 has '+item_class' => ( default => 'User' );
48
49 has_field 'name' => ( type => 'Text' );
50 has_field 'age' => ( type => 'PosInteger', apply => [ 'MinimumAge' ] );
51 has_field 'birthdate' => ( type => 'DateTime' );
52 has_field 'birthdate.month' => ( type => 'Month' );
53 has_field 'birthdate.day' => ( type => 'MonthDay' );
54 has_field 'birthdate.year' => ( type => 'Year' );
55 has_field 'hobbies' => ( type => 'Multiple' );
56 has_field 'address' => ( type => 'Text' );
57 has_field 'city' => ( type => 'Text' );
58 has_field 'state' => ( type => 'Select' );
59 has_field 'email' => ( type => 'Email' );
60
61 has '+dependency' => ( default => sub {
62 [ ['address', 'city', 'state'], ]
63 }
64 );
65
66 subtype 'MinimumAge'
67 => as 'Int'
68 => where { $_ > 13 }
69 => message { "You are not old enough to register" };
70
71 no HTML::FormHandler::Moose;
72 1;
73
74 A dynamic form - one that does not use a custom form class - may be
75 created using the 'field_list' attribute to set fields:
76
77 my $form = HTML::FormHandler->new(
78 name => 'user_form',
79 item => $user,
80 field_list => [
81 'username' => {
82 type => 'Text',
83 apply => [ { check => qr/^[0-9a-z]*\z/,
84 message => 'Contains invalid characters' } ],
85 },
86 'select_bar' => {
87 type => 'Select',
88 options => \@select_options,
89 multiple => 1,
90 size => 4,
91 },
92 ],
93 );
94
95 FormHandler does not provide a custom controller for Catalyst because
96 it isn't necessary. Interfacing to FormHandler is only a couple of
97 lines of code. See HTML::FormHandler::Manual::Catalyst for more
98 details, or
99 Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormHandler.
100
102 *** Although documentation in this file provides some overview, it is
103 mainly intended for API documentation. See
104 HTML::FormHandler::Manual::Intro for an introduction, with links to
105 other documentation.
106
107 HTML::FormHandler maintains a clean separation between form
108 construction and form rendering. It allows you to define your forms and
109 fields in a number of flexible ways. Although it provides renderers for
110 HTML, you can define custom renderers for any kind of presentation.
111
112 HTML::FormHandler allows you to define form fields and validators. It
113 can be used for both database and non-database forms, and will
114 automatically update or create rows in a database. It can be used to
115 process structured data that doesn't come from an HTML form.
116
117 One of its goals is to keep the controller/application program
118 interface as simple as possible, and to minimize the duplication of
119 code. In most cases, interfacing your controller to your form is only a
120 few lines of code.
121
122 With FormHandler you shouldn't have to spend hours trying to figure out
123 how to make a simple HTML change that would take one minute by hand.
124 Because you _can_ do it by hand. Or you can automate HTML generation as
125 much as you want, with template widgets or pure Perl rendering classes,
126 and stay completely in control of what, where, and how much is done
127 automatically. You can define custom renderers and display your
128 rendered forms however you want.
129
130 You can split the pieces of your forms up into logical parts and
131 compose complete forms from FormHandler classes, roles, fields,
132 collections of validations, transformations and Moose type constraints.
133 You can write custom methods to process forms, add any attribute you
134 like, and use Moose method modifiers. FormHandler forms are Perl
135 classes, so there's a lot of flexibility in what you can do.
136
137 HTML::FormHandler provides rendering through roles which are applied to
138 form and field classes (although there's no reason you couldn't write a
139 renderer as an external object either). There are currently two
140 flavors: all-in-one solutions like HTML::FormHandler::Render::Simple
141 and HTML::FormHandler::Render::Table that contain methods for rendering
142 field widget classes, and the HTML::FormHandler::Widget roles, which
143 are more atomic roles which are automatically applied to fields and
144 form. See HTML::FormHandler::Manual::Rendering for more details. (And
145 you can easily use hand-built forms - FormHandler doesn't care.)
146
147 The typical application for FormHandler would be in a Catalyst,
148 DBIx::Class, Template Toolkit web application, but use is not limited
149 to that. FormHandler can be used in any Perl application.
150
151 More Formhandler documentation and a tutorial can be found in the
152 manual at HTML::FormHandler::Manual.
153
155 Creating a form with 'new'
156 The new constructor takes name/value pairs:
157
158 MyForm->new(
159 item => $item,
160 );
161
162 No attributes are required on new. The form's fields will be built from
163 the form definitions. If no initial data object or defaults have been
164 provided, the form will be empty. Most attributes can be set on either
165 'new' or 'process'. The common attributes to be passed in to the
166 constructor for a database form are either item_id and schema or item:
167
168 item_id - database row primary key
169 item - database row object
170 schema - (for DBIC) the DBIx::Class schema
171
172 The following are sometimes passed in, but are also often set in the
173 form class:
174
175 item_class - source name of row
176 dependency - (see dependency)
177 field_list - an array of field definitions
178 init_object - a hashref or object to provide initial values
179
180 Examples of creating a form object with new:
181
182 my $form = MyApp::Form::User->new;
183
184 # database form using a row object
185 my $form = MyApp::Form::Member->new( item => $row );
186
187 # a dynamic form (no form class has been defined)
188 my $form = HTML::FormHandler::Model::DBIC->new(
189 item_id => $id,
190 item_class => 'User',
191 schema => $schema,
192 field_list => [
193 name => 'Text',
194 active => 'Boolean',
195 submit_btn => 'Submit',
196 ],
197 );
198
199 See the model class for more information about 'item', 'item_id',
200 'item_class', and 'schema' (for the DBIC model).
201 HTML::FormHandler::Model::DBIC.
202
203 FormHandler forms are handled in two steps: 1) create with 'new', 2)
204 handle with 'process'. FormHandler doesn't care whether most parameters
205 are set on new or process or update, but a 'field_list' argument must
206 be passed in on 'new' since the fields are built at construction time.
207
208 If you want to update field attributes on the 'process' call, you can
209 use an 'update_field_list' or 'defaults' hashref attribute , or
210 subclass update_fields in your form. The 'update_field_list' hashref
211 can be used to set any field attribute. The 'defaults' hashref will
212 update only the 'default' attribute in the field. (There are a lot of
213 ways to set defaults. See HTML::FormHandler::Manual::Defaults.)
214
215 $form->process( defaults => { foo => 'foo_def', bar => 'bar_def' } );
216 $form->process( update_field_list => { foo => { label => 'New Label' } });
217
218 Field results are built on the 'new' call, but will then be re-built on
219 the process call. If you always use 'process' before rendering the
220 form, accessing fields, etc, you can set the 'no_preload' flag to skip
221 this step.
222
223 Processing the form
224 process
225
226 Call the 'process' method on your form to perform validation and
227 update. A database form must have either an item (row object) or a
228 schema, item_id (row primary key), and item_class (usually set in the
229 form). A non-database form requires only parameters.
230
231 $form->process( item => $book, params => $c->req->parameters );
232 $form->process( item_id => $item_id,
233 schema => $schema, params => $c->req->parameters );
234 $form->process( params => $c->req->parameters );
235
236 This process method returns the 'validated' flag ("$form->validated").
237 If it is a database form and the form validates, the database row will
238 be updated.
239
240 After the form has been processed, you can get a parameter hashref
241 suitable for using to fill in the form from "$form->fif". A hash of
242 inflated values (that would be used to update the database for a
243 database form) can be retrieved with "$form->value".
244
245 If you don't want to update the database on this process call, you can
246 set the 'no_update' flag:
247
248 $form->process( item => $book, params => $params, no_update => 1 );
249
250 params
251
252 Parameters are passed in when you call 'process'. HFH gets data to
253 validate and store in the database from the params hash. If the params
254 hash is empty, no validation is done, so it is not necessary to check
255 for POST before calling "$form->process". (Although see the 'posted'
256 option for complications.)
257
258 Params can either be in the form of CGI/HTTP style params:
259
260 {
261 user_name => "Joe Smith",
262 occupation => "Programmer",
263 'addresses.0.street' => "999 Main Street",
264 'addresses.0.city' => "Podunk",
265 'addresses.0.country' => "UT",
266 'addresses.0.address_id' => "1",
267 'addresses.1.street' => "333 Valencia Street",
268 'addresses.1.city' => "San Francisco",
269 'addresses.1.country' => "UT",
270 'addresses.1.address_id' => "2",
271 }
272
273 or as structured data in the form of hashes and lists:
274
275 {
276 addresses => [
277 {
278 city => 'Middle City',
279 country => 'GK',
280 address_id => 1,
281 street => '101 Main St',
282 },
283 {
284 city => 'DownTown',
285 country => 'UT',
286 address_id => 2,
287 street => '99 Elm St',
288 },
289 ],
290 'occupation' => 'management',
291 'user_name' => 'jdoe',
292 }
293
294 CGI style parameters will be converted to hashes and lists for HFH to
295 operate on.
296
297 posted
298
299 Note that FormHandler by default uses empty params as a signal that the
300 form has not actually been posted, and so will not attempt to validate
301 a form with empty params. Most of the time this works OK, but if you
302 have a small form with only the controls that do not return a post
303 parameter if unselected (checkboxes and select lists), then the form
304 will not be validated if everything is unselected. For this case you
305 can either add a hidden field as an 'indicator', or use the 'posted'
306 flag:
307
308 $form->process( posted => ($c->req->method eq 'POST'), params => ... );
309
310 The 'posted' flag also works to prevent validation from being performed
311 if there are extra params in the params hash and it is not a 'POST'
312 request.
313
314 Getting data out
315 fif (fill in form)
316
317 If you don't use FormHandler rendering and want to fill your form
318 values in using some other method (such as with HTML::FillInForm or
319 using a template) this returns a hash of values that are equivalent to
320 params which you may use to fill in your form.
321
322 The fif value for a 'title' field in a TT form:
323
324 [% form.fif.title %]
325
326 Or you can use the 'fif' method on individual fields:
327
328 [% form.field('title').fif %]
329
330 If you use FormHandler to render your forms or field you probably won't
331 use these methods.
332
333 value
334
335 Returns a hashref of all field values. Useful for non-database forms,
336 or if you want to update the database yourself. The 'fif' method
337 returns a hashref with the field names for the keys and the field's
338 'fif' for the values; 'value' returns a hashref with the field
339 accessors for the keys, and the field's 'value' (possibly inflated) for
340 the values.
341
342 Forms containing arrays to be processed with
343 HTML::FormHandler::Field::Repeatable will have parameters with dots and
344 numbers, like 'addresses.0.city', while the values hash will transform
345 the fields with numbers to arrays.
346
347 Accessing and setting up fields
348 Fields are declared with a number of attributes which are defined in
349 HTML::FormHandler::Field. If you want additional attributes you can
350 define your own field classes (or apply a role to a field class - see
351 HTML::FormHandler::Manual::Cookbook). The field 'type' (used in field
352 definitions) is the short class name of the field class, used when
353 searching the 'field_name_space' for the field class.
354
355 has_field
356
357 The most common way of declaring fields is the 'has_field' syntax.
358 Using the 'has_field' syntax sugar requires " use
359 HTML::FormHandler::Moose; " or " use HTML::FormHandler::Moose::Role; "
360 in a role. See HTML::FormHandler::Manual::Intro
361
362 use HTML::FormHandler::Moose;
363 has_field 'field_name' => ( type => 'FieldClass', .... );
364
365 field_list
366
367 A 'field_list' is an array of field definitions which can be used as an
368 alternative to 'has_field' in small, dynamic forms to create fields.
369
370 field_list => [
371 field_one => {
372 type => 'Text',
373 required => 1
374 },
375 field_two => 'Text,
376 ]
377
378 The field_list array takes elements which are either a field_name key
379 pointing to a 'type' string or a field_name key pointing to a hashref
380 of field attributes. You can also provide an array of hashref elements
381 with the name as an additional attribute. The field list can be set
382 inside a form class, when you want to add fields to the form depending
383 on some other state, although you can also create all the fields and
384 set some of them inactive.
385
386 sub field_list {
387 my $self = shift;
388 my $fields = $self->schema->resultset('SomeTable')->
389 search({user_id => $self->user_id, .... });
390 my @field_list;
391 while ( my $field = $fields->next )
392 {
393 < create field list >
394 }
395 return \@field_list;
396 }
397
398 update_field_list
399
400 Used to dynamically set particular field attributes on the 'process'
401 (or 'run') call. (Will not create fields.)
402
403 $form->process( update_field_list => {
404 foo_date => { format => '%m/%e/%Y', date_start => '10-01-01' } },
405 params => $params );
406
407 The 'update_field_list' is processed by the 'update_fields' form
408 method, which can also be used in a form to do specific field updates:
409
410 sub update_fields {
411 my $self = shift;
412 $self->field('foo')->temp( 'foo_temp' );
413 $self->field('bar')->default( 'foo_value' );
414 $self->next::method();
415 }
416
417 (Note that you although you can set a field's 'default', you can't set
418 a field's 'value' directly here, since it will be overwritten by the
419 validation process. Set the value in a field validation method.)
420
421 update_subfields
422
423 Yet another way to provide settings for the field, except this one is
424 intended for use in roles and compound fields, and is only executed
425 when the form is initially built. It takes the same field name keys as
426 'update_field_list', plus 'all', 'by_flag', and 'by_type'.
427
428 sub build_update_subfields {{
429 all => { tags => { wrapper_tag => 'p' } },
430 foo => { element_class => 'blue' },
431 }}
432
433 The 'all' hash key will apply updates to all fields. (Conflicting
434 attributes in a field definition take precedence.)
435
436 The 'by_flag' hash key will apply updates to fields with a particular
437 flag. The currently supported subkeys are 'compound', 'contains', and
438 'repeatable'. (For repeatable instances, in addition to 'contains' you
439 can also use the 'repeatable' key and the 'init_contains' attribute.)
440 This is useful for turning on the rendering wrappers for compounds and
441 repeatables, which are off by default. (The repeatable instances are
442 wrapped by default.)
443
444 sub build_update_subfields {{
445 by_flag => { compound => { do_wrapper => 1 } },
446 by_type => { Select => { element_class => ['sel_elem'] } },
447 }}
448
449 The 'by_type' hash key will provide values to all fields of a
450 particular type.
451
452 defaults
453
454 This is a more specialized version of the 'update_field_list'. It can
455 be used to provide 'default' settings for fields, in a shorthand way
456 (you don't have to say 'default' for every field).
457
458 $form->process( defaults => { foo => 'this_foo', bar => 'this_bar' }, ... );
459
460 active/inactive
461
462 A field can be marked 'inactive' and set to active at new or process
463 time by specifying the field name in the 'active' array:
464
465 has_field 'foo' => ( type => 'Text', inactive => 1 );
466 ...
467 my $form = MyApp::Form->new( active => ['foo'] );
468 ...
469 $form->process( active => ['foo'] );
470
471 Or a field can be a normal active field and set to inactive at new or
472 process time:
473
474 has_field 'bar';
475 ...
476 my $form = MyApp::Form->new( inactive => ['foo'] );
477 ...
478 $form->process( inactive => ['foo'] );
479
480 Fields specified as active/inactive on new will have the form's
481 inactive/active arrayref cleared and the field's inactive flag set
482 appropriately, so that the state will be effective for the life of the
483 form object. Fields specified as active/inactive on 'process' will have
484 the field's '_active' flag set for the life of the request (the _active
485 flag will be cleared when the form is cleared).
486
487 The 'sorted_fields' method returns only active fields, sorted according
488 to the 'order' attribute. The 'fields' method returns all fields.
489
490 foreach my $field ( $self->sorted_fields ) { ... }
491
492 You can test whether a field is active by using the field 'is_active'
493 and 'is_inactive' methods.
494
495 field_name_space
496
497 Use to look for field during form construction. If a field is not found
498 with the field_name_space (or HTML::FormHandler/HTML::FormHandlerX),
499 the 'type' must start with a '+' and be the complete package name.
500
501 fields
502
503 The array of fields, objects of HTML::FormHandler::Field or its
504 subclasses. A compound field will itself have an array of fields, so
505 this is a tree structure.
506
507 sorted_fields
508
509 Returns those fields from the fields array which are currently active.
510 This is the method that returns the fields that are looped through when
511 rendering.
512
513 field($name), subfield($name)
514
515 'field' is the method that is usually called to access a field:
516
517 my $title = $form->field('title')->value;
518 [% f = form.field('title') %]
519
520 my $city = $form->field('addresses.0.city')->value;
521
522 Pass a second true value to die on errors.
523
524 Since fields are searched for using the form as a base, if you want to
525 find a sub field in a compound field method, the 'subfield' method may
526 be more useful, since you can search starting at the current field. The
527 'chained' method also works:
528
529 -- in a compound field --
530 $self->field('media.caption'); # fails
531 $self->field('media')->field('caption'); # works
532 $self->subfield('media.caption'); # works
533
534 Constraints and validation
535 Most validation is performed on a per-field basis, and there are a
536 number of different places in which validation can be performed.
537
538 See also HTML::FormHandler::Manual::Validation.
539
540 Form class validation for individual fields
541
542 You can define a method in your form class to perform validation on a
543 field. This method is the equivalent of the field class validate
544 method except it is in the form class, so you might use this validation
545 method if you don't want to create a field subclass.
546
547 It has access to the form ($self) and the field. This method is called
548 after the field class 'validate' method, and is not called if the value
549 for the field is empty ('', undef). (If you want an error message when
550 the field is empty, use the 'required' flag and message or the form
551 'validate' method.) The name of this method can be set with
552 'set_validate' on the field. The default is 'validate_' plus the field
553 name:
554
555 sub validate_testfield { my ( $self, $field ) = @_; ... }
556
557 If the field name has dots they should be replaced with underscores.
558
559 Note that you can also provide a coderef which will be a method on the
560 field:
561
562 has_field 'foo' => ( validate_method => \&validate_foo );
563
564 validate
565
566 This is a form method that is useful for cross checking values after
567 they have been saved as their final validated value, and for performing
568 more complex dependency validation. It is called after all other field
569 validation is done, and whether or not validation has succeeded, so it
570 has access to the post-validation values of all the fields.
571
572 This is the best place to do validation checks that depend on the
573 values of more than one field.
574
575 Accessing errors
576 Also see HTML::FormHandler::Manual::Errors.
577
578 Set an error in a field with "$field->add_error('some error string');".
579 Set a form error not tied to a specific field with
580 "$self->add_form_error('another error string');". The 'add_error' and
581 'add_form_error' methods call localization. If you want to skip
582 localization for a particular error, you can use 'push_errors' or
583 'push_form_errors' instead.
584
585 has_errors - returns true or false
586 error_fields - returns list of fields with errors
587 errors - returns array of error messages for the entire form
588 num_errors - number of errors in form
589
590 Each field has an array of error messages. (errors, has_errors,
591 num_errors, clear_errors)
592
593 $form->field('title')->errors;
594
595 Compound fields also have an array of error_fields.
596
597 Clear form state
598 The clear method is called at the beginning of 'process' if the form
599 object is reused, such as when it is persistent in a Moose attribute,
600 or in tests. If you add other attributes to your form that are set on
601 each request, you may need to clear those yourself.
602
603 If you do not call the form's 'process' method on a persistent form,
604 such as in a REST controller's non-POST method, or if you only call
605 process when the form is posted, you will also need to call
606 "$form->clear".
607
608 The 'run' method which returns a result object always performs 'clear',
609 to keep the form object clean.
610
611 Miscellaneous attributes
612 name
613
614 The form's name. Useful for multiple forms. Used for the form element
615 'id'. When 'html_prefix' is set it is used to construct the field 'id'
616 and 'name'. The default is "form" + a one to three digit random
617 number. Because the HTML standards have flip-flopped on whether the
618 HTML form element can contain a 'name' attribute, please set a name
619 attribute using 'form_element_attr'.
620
621 init_object
622
623 An 'init_object' may be used instead of the 'item' to pre-populate the
624 values in the form. This can be useful when populating a form from
625 default values stored in a similar but different object than the one
626 the form is creating. The 'init_object' should be either a hash or the
627 same type of object that the model uses (a DBIx::Class row for the DBIC
628 model). It can be set in a variety of ways:
629
630 my $form = MyApp::Form->new( init_object => { .... } );
631 $form->process( init_object => {...}, ... );
632 has '+init_object' => ( default => sub { { .... } } );
633 sub init_object { my $self = shift; .... }
634
635 The method version is useful if the organization of data in your form
636 does not map to an existing or database object in an automatic way, and
637 you need to create a different type of object for initialization. (You
638 might also want to do 'update_model' yourself.)
639
640 Also see the 'use_init_obj_over_item' and the
641 'use_init_obj_when_no_accessor_in_item' flags, if you want to provide
642 both an item and an init_object, and use the values from the
643 init_object.
644
645 The 'use_init_obj_when_no_accessor_in_item' flag is particularly useful
646 when some of the fields in your form come from the database and some
647 are process or environment type flags that are not in the database. You
648 can provide defaults from both a database row and an 'init_object.
649
650 ctx
651
652 Place to store application context for your use in your form's methods.
653
654 language_handle
655
656 See 'language_handle' and '_build_language_handle' in
657 HTML::FormHandler::TraitFor::I18N.
658
659 dependency
660
661 Arrayref of arrayrefs of fields. If one of a group of fields has a
662 value, then all of the group are set to 'required'.
663
664 has '+dependency' => ( default => sub { [
665 ['street', 'city', 'state', 'zip' ],] }
666 );
667
668 Flags
669 validated, is_valid
670
671 Flag that indicates if form has been validated. You might want to use
672 this flag if you're doing something in between process and returning,
673 such as setting a stash key. ('is_valid' is a synonym for this flag)
674
675 $form->process( ... );
676 $c->stash->{...} = ...;
677 return unless $form->validated;
678
679 ran_validation
680
681 Flag to indicate that validation has been run. This flag will be false
682 when the form is initially loaded and displayed, since validation is
683 not run until FormHandler has params to validate.
684
685 verbose, dump, peek
686
687 Flag to dump diagnostic information. See 'dump_fields' and
688 'dump_validated'. 'Peek' can be useful in diagnosing bugs. It will
689 dump a brief listing of the fields and results.
690
691 $form->process( ... );
692 $form->peek;
693
694 html_prefix
695
696 Flag to indicate that the form name is used as a prefix for fields in
697 an HTML form. Useful for multiple forms on the same HTML page. The
698 prefix is stripped off of the fields before creating the internal field
699 name, and added back in when returning a parameter hash from the 'fif'
700 method. For example, the field name in the HTML form could be
701 "book.borrower", and the field name in the FormHandler form (and the
702 database column) would be just "borrower".
703
704 has '+name' => ( default => 'book' );
705 has '+html_prefix' => ( default => 1 );
706
707 Also see the Field attribute "html_name", a convenience function which
708 will return the form name + "." + field full_name
709
710 is_html5
711
712 Flag to indicate the fields will render using specialized attributes
713 for html5. Set to 0 by default.
714
715 use_defaults_over_obj
716
717 The 'normal' precedence is that if there is an accessor in the
718 item/init_object that value is used and not the 'default'. This flag
719 makes the defaults of higher precedence. Mainly useful if providing an
720 empty row on create.
721
722 use_init_obj_over_item
723
724 If you are providing both an item and an init_object, and want the
725 init_object to be used for defaults instead of the item.
726
727 For use in HTML
728 form_element_attr - hashref for setting arbitrary HTML attributes
729 set in form with: sub build_form_element_attr {...}
730 form_element_class - arrayref for setting form tag class
731 form_wrapper_attr - hashref for form wrapper element attributes
732 set in form with: sub build_form_wrapper_attr {...}
733 form_wrapper_class - arrayref for setting wrapper class
734 do_form_wrapper - flag to wrap the form
735 http_method - For storing 'post' or 'get'
736 action - Store the form 'action' on submission. No default value.
737 uuid - generates a string containing an HTML field with UUID
738 form_tags - hashref of tags for use in rendering code
739 widget_tags - rendering tags to be transferred to fields
740
741 Discouraged (use form_element_attr instead):
742
743 style - adds a 'style' attribute to the form tag
744 enctype - Request enctype
745
746 Note that the form tag contains an 'id' attribute which is set to the
747 form name. The standards have been flip-flopping over whether a 'name'
748 attribute is valid. It can be set with 'form_element_attr'.
749
750 The rendering of the HTML attributes is done using the 'process_attrs'
751 function and the 'element_attributes' or 'wrapper_attributes' method,
752 which adds other attributes in for backward compatibility, and calls
753 the 'html_attributes' hook.
754
755 For HTML attributes, there is a form method hook, 'html_attributes',
756 which can be used to customize/modify/localize form & field HTML
757 attributes. Types: element, wrapper, label, form_element,
758 form_wrapper, checkbox_label
759
760 sub html_attributes {
761 my ( $self, $obj, $type, $attrs, $result ) = @_;
762
763 # obj is either form or field
764 $attr->{class} = 'label' if $type eq 'label';
765 $attr->{placeholder} = $self->_localize($attr->{placeholder})
766 if exists $attr->{placeholder};
767 return $attr;
768 }
769
770 Also see the documentation in HTML::FormHandler::Field and in
771 HTML::FormHandler::Manual::Rendering.
772
774 IRC:
775
776 Join #formhandler on irc.perl.org
777
778 Mailing list:
779
780 http://groups.google.com/group/formhandler
781
782 Code repository:
783
784 http://github.com/gshank/html-formhandler/tree/master
785
786 Bug tracker:
787
788 https://rt.cpan.org/Dist/Display.html?Name=HTML-FormHandler
789
791 HTML::FormHandler::Manual
792
793 HTML::FormHandler::Manual::Tutorial
794
795 HTML::FormHandler::Manual::Intro
796
797 HTML::FormHandler::Manual::Templates
798
799 HTML::FormHandler::Manual::Cookbook
800
801 HTML::FormHandler::Manual::Rendering
802
803 HTML::FormHandler::Manual::Reference
804
805 HTML::FormHandler::Field
806
807 HTML::FormHandler::Model::DBIC
808
809 HTML::FormHandler::Render::Simple
810
811 HTML::FormHandler::Render::Table
812
813 HTML::FormHandler::Moose
814
816 gshank: Gerda Shank <gshank@cpan.org>
817
818 zby: Zbigniew Lukasiak <zby@cpan.org>
819
820 t0m: Tomas Doran <bobtfish@bobtfish.net>
821
822 augensalat: Bernhard Graf <augensalat@gmail.com>
823
824 cubuanic: Oleg Kostyuk <cub.uanic@gmail.com>
825
826 rafl: Florian Ragwitz <rafl@debian.org>
827
828 mazpe: Lester Ariel Mesa
829
830 dew: Dan Thomas
831
832 koki: Klaus Ita
833
834 jnapiorkowski: John Napiorkowski
835
836 lestrrat: Daisuke Maki
837
838 hobbs: Andrew Rodland
839
840 Andy Clayton
841
842 boghead: Bryan Beeley
843
844 Csaba Hetenyi
845
846 Eisuke Oishi
847
848 Lian Wan Situ
849
850 Murray
851
852 Nick Logan
853
854 Vladimir Timofeev
855
856 diegok: Diego Kuperman
857
858 ijw: Ian Wells
859
860 amiri: Amiri Barksdale
861
862 ozum: Ozum Eldogan
863
864 lukast: Lukas Thiemeier
865
866 Initially based on the source code of Form::Processor by Bill Moseley
867
869 FormHandler Contributors - see HTML::FormHandler
870
872 This software is copyright (c) 2017 by Gerda Shank.
873
874 This is free software; you can redistribute it and/or modify it under
875 the same terms as the Perl 5 programming language system itself.
876
877
878
879perl v5.32.1 2021-01-27 HTML::FormHandler(3)