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
47       This returns a hash mapping all the column names of the class to
48       HTML::Element objects representing form widgets.
49
50       to_field($field [, $how])
51
52       This maps an individual column to a form element. The "how" argument
53       can be used to force the field type into one of "textfield", "textarea"
54       or "select"; you can use this is you want to avoid the automatic detecā€
55       tion of has-a relationships.
56

CHANGES

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

MAINTAINER

64       Tony Bowden
65

ORIGINAL AUTHOR

67       Simon Cozens
68

BUGS and QUERIES

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

SEE ALSO

80       Class::DBI, Class::DBI::FromCGI, HTML::Element.
81
82
83
84perl v5.8.8                       2005-09-06             Class::DBI::AsForm(3)
Impressum