diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index d47db2d09..c2ffa6f8c 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -33,7 +33,7 @@ Package WebGUI::Form =head1 DESCRIPTION -Base forms package. Eliminates some of the normal code work that goes along with creating forms. Used by the HTMLForm package. +This is a convenience package which provides a simple interface to use all of the form controls without having to load each one seperately, create objects, and call methods. =head1 SYNOPSIS @@ -531,115 +531,6 @@ sub group { } - -#------------------------------------------------------------------- - -=head2 HTMLArea ( hashRef ) - -Returns an HTML area. An HTML area is different than a standard text area in that it provides rich edit functionality and some special error trapping for HTML and other special characters. - -=head3 name - -The name field for this form element. - -=head3 richEditId - -An asset Id of a rich editor to display for this field. - -=head3 value - -The default value for this form element. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 wrap - -The method for wrapping text in the text area. Defaults to "virtual". There should be almost no reason to specify this. - -=head3 rows - -The number of characters tall this form element should be. There should be no reason for anyone to specify this. - -=head3 columns - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=head3 defaultValue - -This will be used if no value is specified. - -=cut - -sub HTMLArea { - my $params = shift; - my $rows = $params->{rows} || ($session{setting}{textAreaRows}+20); - my $columns = $params->{columns} || ($session{setting}{textAreaCols}+10); - my $richEditId = $params->{richEditId} || $session{setting}{richEditor} || "PBrichedit000000000001"; - my $output = textarea({ - name=>$params->{name}, - value=>$params->{value}, - wrap=>$params->{wrap}, - columns=>$columns, - rows=>$rows, - extras=>$params->{extras}.' onBlur="fixChars(this.form.'.$params->{name}.')" id="'.$params->{name}.'"'.' mce_editable="true" ', - defaultValue=>$params->{defaultValue} - }); - WebGUI::Style::setScript($session{config}{extrasURL}.'/textFix.js',{ type=>'text/javascript' }); - $output .= WebGUI::Asset::RichEdit->new($richEditId)->getRichEditor($params->{name}); - return $output; -} - -#------------------------------------------------------------------- - -=head2 integer ( hashRef ) - -Returns an integer field. - -=head3 name - -The name field for this form element. - -=head3 value - -The default value for this form element. - -=head3 maxlength - -The maximum number of characters to allow in this form element. Defaults to 11. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 size - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=head3 defaultValue - -This will be used if no value is specified. - -=cut - -sub integer { - my $params = shift; - WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' }); - return text({ - name=>$params->{name}, - value=>$params->{value}, - defaultValue=>$params->{defaultValue} || 0, - size=>$params->{size} || 11, - extras=>'onKeyUp="doInputCheck(this.form.'.$params->{name}.',\'0123456789-\')" '.$params->{extras}, - maxlength=>$params->{maxlength} - }); -} - #------------------------------------------------------------------- =head2 interval ( hashRef ) diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm new file mode 100644 index 000000000..0fe25f98a --- /dev/null +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -0,0 +1,131 @@ +package WebGUI::Form::HTMLArea; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2005 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 strict; +use base 'WebGUI::Form::textarea'; +use WebGUI::Asset::RichEdit; +use WebGUI::HTML; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::HTMLArea + +=head1 DESCRIPTION + +Creates an HTML Area form control if the user's browser supports it. This basically puts a word processor in the field for them. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::textarea. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 rows + +The number of rows (in characters) tall the box should be. Defaults to the setting textAreaRows + 20. + +=head4 columns + +The number of columns (in characters) wide the box should be. Defaults to the setting textAreaCols + 10. + +=head4 richEditId + +The ID of the WebGUI::Asset::RichEdit object to load. Defaults to the richEditor setting or "PBrichedit000000000001" if that's not set. + +=head + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + rows=>{ + defaultValue=> $session{setting}{textAreaRows}+20 + }, + columns=>{ + defaultValue=> $session{setting}{textAreaCols}+10 + }, + richEditId=>{ + defaultValue=>$session{setting}{richEditor} || "PBrichedit000000000001" + } + }); + return $class->SUPER::definition($definition); +} + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("477","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the value of this form field after stipping unwanted tags like . + +=cut + +sub getValueFromPost { + my $self = shift; + return WebGUI::HTML::cleanSegment($self->SUPER::getValueFromPost()); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an HTML area field. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/textFix.js',{ type=>'text/javascript' }); + $self->{extras} .= ' onBlur="fixChars(this.form.'.$self->{name}.')" id="'.$self->{name}.'"'.' mce_editable="true" '; + return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor($self->{name}); +} + + +1; + diff --git a/lib/WebGUI/Form/codearea.pm b/lib/WebGUI/Form/codearea.pm index 3e0334308..9077e9de4 100644 --- a/lib/WebGUI/Form/codearea.pm +++ b/lib/WebGUI/Form/codearea.pm @@ -15,7 +15,7 @@ package WebGUI::Form::codearea; =cut use strict; -use base 'WebGUI::Form::text'; +use base 'WebGUI::Form::textarea'; use WebGUI::International; use WebGUI::Session; use WebGUI::Style; diff --git a/lib/WebGUI/Form/integer.pm b/lib/WebGUI/Form/integer.pm new file mode 100644 index 000000000..89159ee23 --- /dev/null +++ b/lib/WebGUI/Form/integer.pm @@ -0,0 +1,129 @@ +package WebGUI::Form::integer; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2005 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 strict; +use base 'WebGUI::Form::text'; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Style; + +=head1 NAME + +Package WebGUI::Form::integer + +=head1 DESCRIPTION + +Creates a zip code form field. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::text. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the superclass for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 maxlength + +Defaults to 11. Determines the maximum number of characters allowed in this field. + +=head4 defaultValue + +Defaults to 0. Used if no value is specified. + +=head4 size + +Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + maxlength=>{ + defaultValue=> 11 + }, + defaultValue=>{ + defaultValue=>0 + }, + size=>{ + defaultValue=>11 + } + }); + return $class->SUPER::definition($definition); +} + + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("482","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the integer from the form post, or returns 0 if the post result is invalid. + +=cut + +sub getValueFromPost { + my $self = shift; + my $value = $session{cgi}->param($self->{name}); + if ($value =~ /^[\d\-]+$/) { + return $value; + } + return 0; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders an input tag of type text. + +=cut + +sub toHtml { + my $self = shift; + WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' }); + $self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789-\')"'; + return $self->SUPER::toHtml; +} + +1; + diff --git a/lib/WebGUI/FormProcessor.pm b/lib/WebGUI/FormProcessor.pm index 0d527d25e..aa4a69748 100644 --- a/lib/WebGUI/FormProcessor.pm +++ b/lib/WebGUI/FormProcessor.pm @@ -25,44 +25,18 @@ Package WebGUI::FormProcessor; =head1 DESCRIPTION -This package helps in the processing of the form variables that are returned from any WebGUI form. +This is a convenience package to the individual form controls. It allows you to get the form post results back without having to load each form control seperately, instanciate an object, and call methods. =head1 SYNOPSIS use WebGUI::FormProcessor; $value = WebGUI::FormProcessor::process("favoriteColor","selectList","black"); - $value = WebGUI::FormProcessor::asset("assetId"); - $value = WebGUI::FormProcessor::checkbox("whichOne"); - $value = WebGUI::FormProcessor::checkList("dayOfWeek"); - $value = WebGUI::FormProcessor::codearea("snippet"); - $value = WebGUI::FormProcessor::color("highlightColor"); - $value = WebGUI::FormProcessor::combo("fruit"); - $value = WebGUI::FormProcessor::contentType("text"); - $value = WebGUI::FormProcessor::date("endDate"); - $value = WebGUI::FormProcessor::dateTime("whenToDoIt"); - $value = WebGUI::FormProcessor::email("emailAddress"); - $value = WebGUI::FormProcessor::fieldType("fieldType"); - $value = WebGUI::FormProcessor::filterContent("javascript"); - $value = WebGUI::FormProcessor::float("distance"); - $value = WebGUI::FormProcessor::group("groupToPost"); - $value = WebGUI::FormProcessor::hidden("wid"); - $value = WebGUI::FormProcessor::hiddenList("colors"); - $value = WebGUI::FormProcessor::HTMLArea("description"); - $value = WebGUI::FormProcessor::integer("size"); - $value = WebGUI::FormProcessor::interval("timeToLive"); - $value = WebGUI::FormProcessor::password("identifier"); - $value = WebGUI::FormProcessor::phone("cellPhone"); - $value = WebGUI::FormProcessor::radio("whichOne"); - $value = WebGUI::FormProcessor::radioList("dayOfWeek"); - $value = WebGUI::FormProcessor::selectList("dayOfWeek"); - $value = WebGUI::FormProcessor::template("templateId"); - $value = WebGUI::FormProcessor::text("firstName"); - $value = WebGUI::FormProcessor::textarea("emailMessage"); - $value = WebGUI::FormProcessor::timeField("wakeupCall"); - $value = WebGUI::FormProcessor::url("homepage"); - $value = WebGUI::FormProcessor::yesNo("happy"); - $value = WebGUI::FormProcessor::zipcode("workZip"); + $value = WebGUI::FormProcessor::someFormControlType("fieldName"); + + Example: + + $value WebGUI::FormProcessor::text("title"); =head1 METHODS @@ -188,23 +162,6 @@ sub hiddenList { } -#------------------------------------------------------------------- - -=head2 HTMLArea ( name ) - -Returns a string of HTML that has been cleaned of header information. - -=head3 name - -The name of the form variable to retrieve. - -=cut - -sub HTMLArea { - return WebGUI::HTML::cleanSegment($session{form}{$_[0]}); -} - - #------------------------------------------------------------------- =head2 integer ( name ) diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 4ef001ca6..b7005b17b 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -556,168 +556,6 @@ sub group { } -#------------------------------------------------------------------- - -=head2 HTMLArea ( name [, label, value, subtext, extras, wrap, rows, columns, uiLevel, defaultValue ] ) - -Adds an HTML area row to this form. An HTML area is different than a standard text area in that it provides rich edit functionality and some special error trapping for HTML and other special characters. - -=head3 name - -The name field for this form element. - -=head3 label - -The left column label for this form row. - -=head3 value - -The default value for this form element. - -=head3 subtext - -Extra text to describe this form element or to provide special instructions. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 wrap - -The method for wrapping text in the text area. Defaults to "virtual". There should be almost no reason to specify this. - -=head3 rows - -The number of characters tall this form element should be. There should be no reason for anyone to specify this. - -=head3 columns - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=head3 uiLevel - -The UI level for this field. See the WebGUI developer's site for details. Defaults to "0". - -=head3 defaultValue - -If no value is specified, this will be used. - -=head3 richEditId - -An asset Id of a rich editor config. Defaults to the default rich editor in the settings. - -=head3 hoverHelp - -A string of text or HTML to be displayed when a user's mouse hover's over a field label. It is meant to describe to the user what to use the field for. - -=cut - -sub HTMLArea { - my ($output); - my ($self, @p) = @_; - my ($name, $label, $value, $subtext, $extras, $wrap, $rows, $columns, $uiLevel, $defaultValue, $richEditId, $hoverHelp) = - rearrange([qw(name label value subtext extras wrap rows columns uiLevel defaultValue richEditId hoverHelp)], @p); - if (_uiLevelChecksOut($uiLevel)) { - $output = WebGUI::Form::HTMLArea({ - "name"=>$name, - "value"=>$value, - "wrap"=>$wrap, - "columns"=>$columns, - "rows"=>$rows, - "extras"=>$extras, - defaultValue=>$defaultValue, - richEditId=>$richEditId - }); - $output .= _subtext($subtext); - $output = $self->_tableFormRow($label,$output,$hoverHelp); - } else { - $output = WebGUI::Form::hidden({ - "name"=>$name, - "value"=>$value, - defaultValue=>$defaultValue - }); - } - $self->{_data} .= $output; -} - -#------------------------------------------------------------------- - -=head2 integer ( name [, label, value, maxlength, extras, subtext, size, uiLevel, defaultValue ] ) - -Adds an integer row to this form. - -=head3 name - -The name field for this form element. - -=head3 label - -The left column label for this form row. - -=head3 value - -The default value for this form element. - -=head3 maxlength - -The maximum number of characters to allow in this form element. Defaults to 11. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 subtext - -Extra text to describe this form element or to provide special instructions. - -=head3 size - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=head3 uiLevel - -The UI level for this field. See the WebGUI developer's site for details. Defaults to "0". - -=head3 defaultValue - -If no value is specified, this will be used. - -=head3 hoverHelp - -A string of text or HTML to be displayed when a user's mouse hover's over a field label. It is meant to describe to the user what to use the field for. - -=cut - -sub integer { - my ($output); - my ($self, @p) = @_; - my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel, $defaultValue, $hoverHelp) = - rearrange([qw(name label value maxlength extras subtext size uiLevel defaultValue hoverHelp)], @p); - if (_uiLevelChecksOut($uiLevel)) { - $output = WebGUI::Form::integer({ - "name"=>$name, - "value"=>$value, - "maxlength"=>$maxlength, - "size"=>$size, - "extras"=>$extras, - defaultValue=>$defaultValue - }); - $output .= _subtext($subtext); - $output = $self->_tableFormRow($label,$output,$hoverHelp); - } else { - $output = WebGUI::Form::hidden({ - "name"=>$name, - "value"=>$value, - "defaultValue"=>$defaultValue - }); - } - $self->{_data} .= $output; -} - #------------------------------------------------------------------- =head2 interval ( name [, label, value, extras, subtext, uiLevel, defaultValue ] )