1HTML::FormHandler::ManuUasle:r:DCaotnatbraisbeu(t3e)d PeHrTlMLD:o:cFuomremnHtaantdiloenr::Manual::Database(3)
2
3
4

NAME

6       HTML::FormHandler::Manual::Database - FormHandler use recipes
7

VERSION

9       version 0.40068
10

SYNOPSIS

12       Manual Index
13
14       Information on interfacing FormHandler forms and fields with a
15       database.  Also see HTML::FormHandler::TraitFor::Model::DBIC.
16

Form Models

18       For a database form, use a model base class that interfaces with the
19       database, such as HTML::FormHandler::Model::DBIC, which needs to be
20       installed as a separate package. There's also a sample 'object' model
21       in HTML::FormHandler::Model::Object, which will update a simple object.
22
23       When using a database model, form field values for the row are
24       retrieved from the database using the field 'accessor' attributes
25       (defaults to field name) as database class accessors.
26
27       FormHandler will use relationships to populate single and multiple
28       selection lists, and validate input. A 'single' relationship is
29       processed by HTML::FormHandler::Field::Compound. A 'has_many'
30       relationship is processed by HTML::FormHandler::Field::Repeatable.
31
32       Do not use database row method names, such as 'delete', as field names
33       in a database form.
34
35       You can pass in either the primary key or a row object to the form. If
36       a primary key (item_id) is passed in, you must also provide the schema.
37       The model will use the item_class (DBIC source name) to fetch the row
38       from the database. If you pass in a row object (item), the schema,
39       item_class, and item_id will be set from the row.
40
41       Executing "$form->process( item => $row, params => $params );" will
42       validate the parameters and then update or create the database row
43       object.
44

Fields that map to database relationships

46   Select
47       A select field will automatically retrieve a select list from the
48       database, if the proper column names are provided. Single selects
49       handle 'belongs_to' relationships, where the related table is used to
50       construct a selection list from the database.
51
52       See also HTML::FormHandler::Field::Select and 'lookup_options' in
53       HTML::FormHandler::TraitFor::Model::DBIC.
54
55   Multiple Select
56       A multiple select is either a 'Select' with multiple => 1 set, or a
57       field of the 'Multiple' type. The name of a Multiple select which pulls
58       options from the database automatically should be the name of the
59       'many_to_many' relationship. The 'value' of the field is derived from
60       the 'has_many' part of the relationship.
61
62       The primary key is used for the 'id' of the select. The 'label' column
63       of the select is assumed to be 'name'. If the label column has a
64       different name, it must be specified with 'label_column'.
65
66       Pertinent attributes:
67
68          label_column
69          active_column
70          sort_column
71
72       See also HTML::FormHandler::Field::Select and
73       HTML::FormHandler::Model::DBIC.
74
75   Compound fields
76       A compound field represents a single relationship to another table.
77       Although most compound relations can be handled without providing a
78       primary key, in some circumstances you may need to provide a PrimaryKey
79       field, or add extra values in update_model.
80
81       See also HTML::FormHandler::Field::Compound.
82
83       The default for compound fields is that if all subfields are empty, the
84       value of the compound field is set to undef (null). For some types of
85       relations, you may want to set the 'not_nullable' flag to force the
86       field to contain all subfields anyway, such as when the related rows
87       are not deleted when empty. See test t/compound/empty.t for a
88       demonstration of the difference in output.
89
90   Repeatable fields
91       The 'Repeatable' field type allows you to update arrays of columns from
92       related tables easily. You will need to provide a 'PrimaryKey' hidden
93       field in the compound field contained in the Repeatable.
94
95         has_field 'addresses' => ( type => 'Repeatable' );
96         has_field 'addresses.address_id' => ( type => 'PrimaryKey' );
97         has_field 'addresses.street';
98         has_field 'addresses.city';
99         has_field 'addresses.state';
100
101       There are some complications with creating Repeatable elements (with
102       the PrimaryKey field set to undef) in a database and re-presenting the
103       form.  See HTML::FormHandler::Field::Repeatable for more info.
104

Flags

106   writeonly
107       Do not read the value from the 'item' when populating the form.
108
109   noupdate
110       Do not update the database with this field, i.e. do not include it in
111       "$form->value".
112

Form generator

114       A DBIC form generator is installed with the
115       HTML::FormHandler::Model::DBIC package. See
116       HTML::FormHandler::Generator::DBIC.
117
118       There's also a role, HTML::FormHandler::TraitFor::DBICFields, that
119       allows simple form fields to be auto-generated from a DBIC result
120       class.
121
122           my $form = HTML::FormHandler::Model::DBIC->new_with_traits(
123               traits => ['HTML::FormHandler::TraitFor::DBICFields'],
124               includes => ['title', 'author' ],
125               field_list => [ 'submit' => { type => 'Submit', value => 'Save', order => 99 } ],
126               item => $book );
127

AUTHOR

129       FormHandler Contributors - see HTML::FormHandler
130
132       This software is copyright (c) 2017 by Gerda Shank.
133
134       This is free software; you can redistribute it and/or modify it under
135       the same terms as the Perl 5 programming language system itself.
136
137
138
139perl v5.30.0                      2019-07H-T2M6L::FormHandler::Manual::Database(3)
Impressum