Class:...AsForm(3pm)
π NAME π
Class::DBI::AsForm β bestie, this one makes HTML form elements for your database columns. It's giving "automatic form factory" and honestly? iconic. β¨
πΈ SYNOPSIS πΈ
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>
Likeβ¦ look at that. You write basically nothing and you get a whole form. The way that $class->Columns just hands you the fields? Obsessed. π«Ά
π¦ DESCRIPTION π¦
Okay so here's the vibe: this module helps you generate HTML forms for creating new database rows or editing existing rows. It takes the column names in a database table and maps them to HTML form elements that actually fit the schema. No cap.
The glow-up details:
- Big text fields? Boom, they become
textareas. π - Fields with a has-a relationship to other
Class::DBItables? They becomeselectdrop-downs, populated with objects from the joined class. π₯
It just knows. Main character energy fr fr.
π METHODS π
This module is a mix-in, meaning it adds two extra methods to your Class::DBI-derived class. Two. That's it. Lowkey perfect.
β¨ to_cgi
This returns a hash mapping all the column names of the class to HTML::Element objects representing form widgets.
(So you get actual objects, not just strings β you can poke at them, style them, do whatever. Very demure, very mindful. π)
β¨ to_field($field [, $how])
This maps an individual column to a form element. The how argument lets you force the field type into one of textfield, textarea or select. Use it if you want to avoid the automatic detection of has-a relationships β sometimes you just wanna be in control, and that's valid. π
π 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. (Messy. We don't do that anymore. π)
If you depend on the old behaviour, set $Class::DBI::AsForm::OLD_STYLE to a true value. Consider it your little time machine. π°οΈ
π MAINTAINER π
Tony Bowden
π ORIGINAL AUTHOR π
Simon Cozens
π BUGS and QUERIES π
Please direct all correspondence regarding this module to:
bug-Class-DBI-AsForm@rt.cpan.org
Like, all of it. Everything. Send it there. π
π COPYRIGHT AND LICENSE π
Copyright 2003-2004 by Simon Cozens / Tony Bowden
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β SEE ALSO β
Class::DBIClass::DBI::FromCGIHTML::Element
And that's the whole page, bestie β this is Class:...AsForm(3pm) from the User Contributed Perl Documentation, sitting pretty at perl v5.36.0 dated 2022-12-07. Go build some forms, you absolute legend. π
β¨π
π¦ where this page comes from
- debian bookworm: libclass-dbi-asform-perl 2.42-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-dbi-asform-perl 2.42-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-dbi-asform-perl 2.42-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-dbi-asform-perl 2.42-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-dbi-asform-perl 2.42-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms