1HTML::FormHandler::ModeUls(e3r)Contributed Perl DocumentHaTtMiLo:n:FormHandler::Model(3)
2
3
4
6 HTML::FormHandler::Model - default model base class
7
9 version 0.40068
10
12 This class defines the base attributes for FormHandler model classes.
13 It is not used directly.
14
16 This is an empty base class that defines methods called by
17 HTML::FormHandler to support interfacing forms with a data store such
18 as a database.
19
20 This module provides instructions on methods to override to create a
21 HTML::FormHandler::Model class to work with a specific object
22 relational mapping (ORM) tool.
23
25 item, build_item
26 The "item" is initialized with "build_item" the first time $form->item
27 is called. "item" must be defined in the model class to fetch the
28 object based on the item id. It should return the item's object.
29 Column values are fetched and updated by calling methods on the
30 returned object.
31
32 For example, with Class::DBI you might return:
33
34 return $self->item_class->retrieve( $self->item_id );
35
36 item_id
37 The id (primary key) of the item (object) that the form is updating or
38 has just created. The model class should have a build_item method that
39 can fetch the object from the item_class for this id.
40
41 item_class
42 "item_class" sets and returns a value used by the model class to access
43 the ORM class related to a form.
44
45 For example:
46
47 has '+item_class' => ( default => 'User' );
48
49 This gives the model class a way to access the data store. If this is
50 not a fixed value (as above) then do not define the method in your
51 subclass and instead set the value when the form is created:
52
53 my $form = MyApp::Form::Users->new( item_class => $class );
54
55 The value can be any scalar (or object) needed by the specific ORM to
56 access the data related to the form.
57
58 A builder for 'item_class' might be to return the class of the 'item'.
59
60 guess_field_type
61 Returns the guessed field type. The field name is passed as the first
62 argument. This is only required if using "Auto" type of fields in your
63 form classes. You could override this in your form class, for example,
64 if you use a field naming convention that indicates the field type.
65
66 The metadata info about the columns can be used to assign types.
67
68 lookup_options
69 Retrieve possible options for a given select field from the database.
70 The default method returns undef.
71
72 Returns an array reference of key/value pairs for the column passed in.
73 These values are used for the values and labels for field types that
74 provide a list of options to select from (e.g. Select, Multiple).
75
76 A 'Select' type field (or a field that inherits from
77 HTML::FormHandler::Field::Select) can set a number of scalars that
78 control how options are looked up:
79
80 label_column() - column that holds the label
81 active_column() - column that indicates if a row is acitve
82 sort_column() - column used for sorting the options
83
84 The default for label_column is "name".
85
86 validate_model
87 Validates fields that are dependent on the model. This is called via
88 the validation process and the model class must at least validate
89 "unique" constraints defined in the form class.
90
91 Any errors on a field found should be set by calling the field's
92 add_error method:
93
94 $field->add_error('Value must be unique in the database');
95
96 The default method does nothing.
97
98 clear_model
99 Clear out any dynamic data for persistent object
100
101 update_model
102 Update the model with validated fields
103
105 FormHandler Contributors - see HTML::FormHandler
106
108 This software is copyright (c) 2017 by Gerda Shank.
109
110 This is free software; you can redistribute it and/or modify it under
111 the same terms as the Perl 5 programming language system itself.
112
113
114
115perl v5.28.1 2017-07-20 HTML::FormHandler::Model(3)