package WebGUI::TabForm; =head1 LEGAL ------------------------------------------------------------------- WebGUI is Copyright 2001-2003 Plain Black LLC. ------------------------------------------------------------------- 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 strict; use WebGUI::Form; use WebGUI::HTMLForm; use WebGUI::Session; =head1 NAME Package WebGUI::TabForm =head1 DESCRIPTION Package that makes creating tab-based forms simple through an object-oriented API. =head1 SYNOPSIS use WebGUI::TabForm; use Tie::IxHash; my %tabs; tie %tabs, 'Tie::IxHash'; %tabs = ( cool=>{ label=>"Cool Tab", uiLevel=>5 }, good=>{ label=>"Good Tab", uiLevel=>8 } ); $tabform = WebGUI::TabForm->new(\%tabs); $tabform->hidden($name, $value); $tabform->submit(\%params); $html = $tabform->print; $HTMLFormObject = $tabform->getTab($tabname); $HTMLFormObject->textarea( -name=>$name, -value=>$value, -label=>$label); The best and easiest way to use this package is to just call the methods on the tabs directly. $tabform->get($tabname)->textarea( -name=>$name, -value=>$value, -label=>$label); =head1 SEE ALSO This package is an extension to WebGUI::HTMLForm. See that package for documentation of its methods. =head1 METHODS These methods are available from this class: =cut #------------------------------------------------------------------- =head2 formHeader ( hashRef ) Replaces the default form header with a new definition. NOTE: This uses the same syntax of the WebGUI::Form::formHeader() method. =cut sub formHeader { $_[0]->{_form} = WebGUI::Form::formHeader($_[1]); } #------------------------------------------------------------------- =head2 getTab ( tabName ) Returns a WebGUI::HTMLForm object based upon a tab name created in the constructor. =over =item tabName The name of the tab to return the form object for. =back =cut sub getTab { return $_[0]->{_tab}{$_[1]}{form}; } #------------------------------------------------------------------- =head2 hidden ( hashRef ) Adds a hidden field to the form. NOTE: This uses the same syntax of the WebGUI::Form::hidden() method. =cut sub hidden { $_[0]->{_hidden} .= WebGUI::Form::hidden($_[1]); } #------------------------------------------------------------------- =head2 new ( tabHashRef ) Constructor. =over =item tabHashRef A hash reference containing the definition of the tabs. It should be constructed like this: use Tie::IxHash; my %tabs; tie %tabs, 'Tie::IxHash'; %tabs = ( cool=>{ label=>"Cool Tab", uiLevel=>5 }, good=>{ label=>"Good Tab", uiLevel=>8 } ); =back =cut sub new { my ($class, $tabs) = @_; foreach my $key (keys %{$tabs}) { $tabs->{$key}{form} = WebGUI::HTMLForm->new; } bless { _submit=>WebGUI::Form::submit(), _form=>WebGUI::Form::formHeader(), _hidden=>"", _tab=>$tabs }, $class; } #------------------------------------------------------------------- =head2 print ( ) Returns an HTML string with all the necessary components to draw the tab form. =cut sub print { my $output = ' '; $output .= $_[0]->{_form}; $output .= $_[0]->{_hidden}; my $i = 1; my $tabs; my $form; foreach my $key (keys %{$_[0]->{_tab}}) { $tabs .= ''.$_[0]->{_tab}{$key}{label}.' '; $form .= '