1HTML::FormFu::Model::HaUssheRrefC(o3n)tributed Perl DocuHmTeMnLt:a:tFioornmFu::Model::HashRef(3)
2
3
4
6 HTML::FormFu::Model::HashRef - handle hashrefs
7
9 version 2.07
10
12 ---
13 elements:
14 - user_id
15 - user_name
16 - type: Repeatable
17 nested_name: addresses
18 elements:
19 - type: Hidden
20 name: id
21 - street
22
23
24 $form->model('HashRef')->default_values( {
25 user_id => 123,
26 user_name => 'Hans',
27 addresses => [
28 { id => 2,
29 street => 'Somewhere' },
30 { id => 3,
31 street => 'Somewhere Else' }
32 ]
33 } );
34
35 $form->default_model('HashRef');
36 my $hashref = $form->model->create();
37
38 # $hashref is very much the same as the hashref you passed to default_values()
39
41 If you need the content of a formular as hashref or for processing with
42 other modules like "JSON" you can use this model.
43
45 create
46 This method creates a hashref from a filled form. This form can be
47 filled by calling "default_values" in HTML::FormFu, default_values of
48 any other model class (e. g. HTML::FormFu::Model::DBIC) or by simply
49 submitting the form.
50
51 If "deflators" is true all deflators are processed (defaults to 1).
52
53 If "options" is true the value of all elements which have options like
54 HTML::FormFu::Element::Select will be transformed.
55
56 ---
57 elements:
58 - type: Select
59 name: select
60 options:
61 - [1, "Foo"]
62 - [2, "Bar"]
63
64 If the value of "select" is 1, create will create this hashref:
65
66 { 'select' => { label => 'Foo', value => 1 } }
67
68 If there is more than one value selected, an arrayref is created
69 instead:
70
71 { 'select' => [ { label => 'Foo', value => 1 },
72 { label => 'Bar', value => 2 } ] }
73
74 If "options" is false, the output will look like this:
75
76 { 'select' => 1 }
77
78 respectively
79
80 { 'select' => [1, 2] }
81
82 "options" is false by default.
83
84 To get a flattened hash, you can set "/flatten" to a true value
85 (defaults to 0). This will generate a hash which uses the nested name
86 of each field as key and the value of this field as hash value. If
87 there is a field which has more than one value, a counter is added. The
88 above example would result in a hash like this using "/flatten":
89
90 { 'select_0' => 1,
91 'select_1' => 2 }
92
93 update
94 Alias for "create".
95
96 default_values
97 Populate a form using a hashref. This hashref has the same format as
98 the output of "create". If "inflators" is true, all inflators will be
99 processed (defaults to 1).
100
102 These methods do not return the model object so chaining is not
103 possible!
104
105 options
106 Adds the label of a value to the hashref if the element has "options"
107 in HTML::FormFu::Role::Element::Group. See "create" for an example.
108 Defaults to 0.
109
110 flatten
111 Flattens the hash using Hash::Flatten. See "create" for an example.
112 Defaults to 0.
113
114 deflators
115 If true, processes deflators in "/create". Defaults to 1.
116
117 inflators
118 If true, processes inflators in "/default_values". Defaults to 1.
119
121 HTML::FormFu, Hash::Flatten
122
124 Moritz Onken, "onken@houseofdesign.de"
125
127 Carl Franks <cpan@fireartist.com>
128
130 This software is copyright (c) 2018 by Carl Franks.
131
132 This is free software; you can redistribute it and/or modify it under
133 the same terms as the Perl 5 programming language system itself.
134
135
136
137perl v5.36.0 2023-01-20 HTML::FormFu::Model::HashRef(3)