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