Class::DBI::AsForm(3pm)

Class::DBI::AsForm3pm

Produce html form elements for database columns

Usage

    package Music::CD;
    use Class::DBI::AsForm;
    use base 'Class::DBI';
    use CGI;
    ...
    sub create_or_edit {
        my $class = shift;
        my %cgi_field = $class->to_cgi;
        return start_form,
               (map { "<b>$_</b>: ". $cgi_field{$_}->as_HTML." <br>" } 
                    $class->Columns),
               end_form;
    }
    # <form method="post"...>
    # Title: <input type="text" name="Title" /> <br>
    # Artist: <select name="Artist"> 
    #           <option value=1>Grateful Dead</option>
    #           ...
    #         </select>
    # ...
    # </form>

Overview

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

Methods

The module is a mix-in which adds two additional methods to your "Class::DBI"-derived class.

to_cgi

This returns a hash mapping all the column names of the class to HTML::Element objects representing form widgets.

to_field($field [, $how])

This maps an individual column to a form element. The "how" argument can be used to force the field type into one of "textfield", "textarea" or "select"; you can use this is you want to avoid the automatic detection of has-a relationships.

Changes

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

Maintainer

Tony Bowden

Original author

Simon Cozens

BUGS and QUERIES

Please direct all correspondence regarding this module to:
[email protected]

Releases

11 releases since Debian 3.1 (Sarge); the text changed 5 times.

  1. 3.1
  2. 4.0–5.0
  3. 6.0
  4. 7–9
  5. 10–11
  6. 12–13

From libclass-dbi-asform-perl 2.42-8 in Debian 13 (Trixie). Parsed by carta from the page's man source.