package WebGUI::HTMLForm;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2008 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use CGI::Util qw(rearrange);
use strict qw(vars refs);
use WebGUI::Form;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::HTMLForm
=head1 DESCRIPTION
Package that makes HTML forms typed data and significantly reduces the code needed for properties pages in WebGUI.
=head1 SYNOPSIS
use WebGUI::HTMLForm;
$f = WebGUI::HTMLForm->new($self->session);
$f->someFormControlType(
name=>"someName",
value=>"someValue"
);
Example:
$f->text(
name=>"title",
value=>"My Big Article"
);
See the list of form control types for details on what's available.
$f->trClass("class"); # Sets a Table Row class
$f->print;
$f->printRowsOnly;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
sub _uiLevelChecksOut {
my $self = shift;
if ($_[0] <= $self->session->user->profileField("uiLevel")) {
return 1;
}
else {
return 0;
}
}
#-------------------------------------------------------------------
=head2 AUTOLOAD ( )
Dynamically creates functions on the fly for all the different form control types.
=cut
sub AUTOLOAD {
our $AUTOLOAD;
my $self = shift;
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
my %params = @_;
$params{uiLevelOverride} ||= $self->{_uiLevelOverride};
$params{rowClass} ||= $self->{_class};
my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, %params ]) };
if ($@) {
$self->session->errorHandler->error($@);
return undef;
}
$self->{_data} .= $control->toHtmlWithWrapper;
}
#-------------------------------------------------------------------
=head2 DESTROY ( )
Disposes of the form object.
=cut
sub DESTROY {
my $self = shift;
$self = undef;
}
#-------------------------------------------------------------------
=head2 fieldSetEnd ( )
Closes a field set that was opened by fieldSetStart();
=cut
sub fieldSetEnd {
my $self = shift;
my $legend = shift;
$self->{_data} .= "\n"
."\n"
."
{_tableExtras}.'" style="width: 100%;">'
."\n";
}
#-------------------------------------------------------------------
=head2 fieldSetStart ( legend )
Adds a field set grouping to the form. Note, must be closed with fieldSetEnd().
=head3 legend
A text label to appear with the field set.
=cut
sub fieldSetStart {
my $self = shift;
my $legend = shift;
$self->{_data} .= "