| 1 |
NAME |
| 2 |
Class::DBI::AsForm - Produce HTML form elements for database columns |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
package Music::CD; |
| 6 |
use Class::DBI::AsForm; |
| 7 |
use base 'Class::DBI'; |
| 8 |
use CGI; |
| 9 |
... |
| 10 |
|
| 11 |
sub create_or_edit { |
| 12 |
my $class = shift; |
| 13 |
my %cgi_field = $class->to_cgi; |
| 14 |
return start_form, |
| 15 |
(map { "<b>$_</b>: ". $cgi_field{$_}->as_HTML." <br>" } |
| 16 |
$class->Columns), |
| 17 |
end_form; |
| 18 |
} |
| 19 |
|
| 20 |
# <form method="post"...> |
| 21 |
# Title: <input type="text" name="Title" /> <br> |
| 22 |
# Artist: <select name="Artist"> |
| 23 |
# <option value=1>Grateful Dead</option> |
| 24 |
# ... |
| 25 |
# </select> |
| 26 |
# ... |
| 27 |
# </form> |
| 28 |
|
| 29 |
DESCRIPTION |
| 30 |
This module helps to generate HTML forms for creating new database rows |
| 31 |
or editing existing rows. It maps column names in a database table to |
| 32 |
HTML form elements which fit the schema. Large text fields are turned |
| 33 |
into textareas, and fields with a has-a relationship to other |
| 34 |
"Class::DBI" tables are turned into select drop-downs populated with |
| 35 |
objects from the joined class. |
| 36 |
|
| 37 |
METHODS |
| 38 |
The module is a mix-in which adds two additional methods to your |
| 39 |
"Class::DBI"-derived class. |
| 40 |
|
| 41 |
to_cgi |
| 42 |
This returns a hash mapping all the column names of the class to |
| 43 |
HTML::Element objects representing form widgets. |
| 44 |
|
| 45 |
to_field($field [, $how]) |
| 46 |
This maps an individual column to a form element. The "how" argument can |
| 47 |
be used to force the field type into one of "textfield", "textarea" or |
| 48 |
"select"; you can use this is you want to avoid the automatic detection |
| 49 |
of has-a relationships. |
| 50 |
|
| 51 |
CHANGES |
| 52 |
Version 1.x of this module returned raw HTML instead of "HTML::Element" |
| 53 |
objects, which made it harder to manipulate the HTML before sending it |
| 54 |
out. If you depend on the old behaviour, set |
| 55 |
$Class::DBI::AsForm::OLD_STYLE to a true value. |
| 56 |
|
| 57 |
MAINTAINER |
| 58 |
Tony Bowden |
| 59 |
|
| 60 |
ORIGINAL AUTHOR |
| 61 |
Simon Cozens |
| 62 |
|
| 63 |
BUGS and QUERIES |
| 64 |
Please direct all correspondence regarding this module to: |
| 65 |
[email protected] |
| 66 |
|
| 67 |
COPYRIGHT AND LICENSE |
| 68 |
Copyright 2003-2004 by Simon Cozens / Tony Bowden |
| 69 |
|
| 70 |
This library is free software; you can redistribute it and/or modify it |
| 71 |
under the same terms as Perl itself. |
| 72 |
|
| 73 |
SEE ALSO |
| 74 |
Class::DBI, Class::DBI::FromCGI, HTML::Element. |
| 75 |
|