1Class::DBI::AsForm(3) User Contributed Perl DocumentationClass::DBI::AsForm(3)
2
3
4

NAME

6       Class::DBI::AsForm - Produce HTML form elements for database columns
7

SYNOPSIS

9           package Music::CD;
10           use Class::DBI::AsForm;
11           use base 'Class::DBI';
12           use CGI;
13           ...
14
15           sub create_or_edit {
16               my $class = shift;
17               my %cgi_field = $class->to_cgi;
18               return start_form,
19                      (map { "<b>$_</b>: ". $cgi_field{$_}->as_HTML." <br>" }
20                           $class->Columns),
21                      end_form;
22           }
23
24           # <form method="post"...>
25           # Title: <input type="text" name="Title" /> <br>
26           # Artist: <select name="Artist">
27           #           <option value=1>Grateful Dead</option>
28           #           ...
29           #         </select>
30           # ...
31           # </form>
32

DESCRIPTION

34       This module helps to generate HTML forms for creating new database rows
35       or editing existing rows. It maps column names in a database table to
36       HTML form elements which fit the schema. Large text fields are turned
37       into textareas, and fields with a has-a relationship to other
38       "Class::DBI" tables are turned into select drop-downs populated with
39       objects from the joined class.
40

METHODS

42       The module is a mix-in which adds two additional methods to your
43       "Class::DBI"-derived class.
44
45   to_cgi
46       This returns a hash mapping all the column names of the class to
47       HTML::Element objects representing form widgets.
48
49   to_field($field [, $how])
50       This maps an individual column to a form element. The "how" argument
51       can be used to force the field type into one of "textfield", "textarea"
52       or "select"; you can use this is you want to avoid the automatic
53       detection of has-a relationships.
54

CHANGES

56       Version 1.x of this module returned raw HTML instead of "HTML::Element"
57       objects, which made it harder to manipulate the HTML before sending it
58       out. If you depend on the old behaviour, set
59       $Class::DBI::AsForm::OLD_STYLE to a true value.
60

MAINTAINER

62       Tony Bowden
63

ORIGINAL AUTHOR

65       Simon Cozens
66

BUGS and QUERIES

68       Please direct all correspondence regarding this module to:
69         bug-Class-DBI-AsForm@rt.cpan.org
70
72       Copyright 2003-2004 by Simon Cozens / Tony Bowden
73
74       This library is free software; you can redistribute it and/or modify it
75       under the same terms as Perl itself.
76

SEE ALSO

78       Class::DBI, Class::DBI::FromCGI, HTML::Element.
79
80
81
82perl v5.38.0                      2023-07-20             Class::DBI::AsForm(3)
Impressum