Skip to content

Commit

Permalink
Item811: use <a> anchor instead of #anchor that relies on a newline; …
Browse files Browse the repository at this point in the history
…do not use SEP with error bullet points as it breaks error feedback and sep=""; update some documentation

git-svn-id: http://svn.foswiki.org/trunk/FormPlugin@2069 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Jan 20, 2009
1 parent 2c15e78 commit 78c587f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
53 changes: 41 additions & 12 deletions data/System/FormPlugin.txt
Expand Up @@ -139,8 +139,8 @@ Most parameters are optional. See below for a detailed explanation.
| =elementcssclass= | The CSS class of the element container. Use CSS class =foswikiFormStep= class to divide the form in steps. |- |- | =elementcssclass="foswikiFormStep"= |
| =noformhtml= | When set to =on= no form html will be written to the page. This is useful to set form parameters for form elements that use a different form, for instance with Foswiki:Extensions.CommentPlugin. |- |- | =noformhtml="on"= |
| =onSubmit= | Function call that is invoked when the user has pressed the submit button of a form. This event happens just before the form is submitted, and your function can return a value of false in order to abort the submission. Note that the function call should include =(this)=. |- |- | =onSubmit="return notify(this)"= |
| =sep= | defaults to =\n= (TML line feed), but can be set to " " or similar to allow FORM to be defined within a table | | "\n" | =sep=" "= |
| =showerrors= | allows you to show validation errors above the form (default), or disable them so you can display them using =%<nop>FORMERROR% | | "above" | =showerrors="off"= |
| =sep= | HTML element separator; defaults to =\n= (TML line feed), but can be set to " " or similar to allow FORM to be defined within a table | | "\n" | =sep=" "= |
| =showerrors= | allows you to show validation errors above the form (default), or disable them so you can display them using =%<nop>FORMERROR%= | | "above" | =showerrors="off"= |

---+++ FORMELEMENT

Expand All @@ -162,11 +162,11 @@ Use =%<nop>URLPARAM{"element_name"}%= to retrieve the value of a submitted form
%BB% =password= - creates a password textfield; otherwise same as =text= \
%BB% =upload= - creates an upload field; when used with parameter =type="upload"= and STARTFORM parameter =action="upload"=, set the =name= to ="filepath"= \
%BB% =textarea= - creates a textarea; use =rows= and =cols= to set the size \
%BB% =select= - creates a variable sized selection box; use =size= to set the visible number of items \
%BB% =select= - creates a variable sized selection box; use =size= to set the visible number of items; use =options= to pass select box values \
%BB% =selectmulti= - same as =select= with multiple items selectable \
%BB% =dropdown= - same as =select= with 1 item visible \
%BB% =checkbox= - creates a set of checkboxes; to put checkboxes on line each set =fieldformat="$e&nbsp;&lt;br&nbsp;/&gt;"= \
%BB% =radio= - creates a set of radio buttons; to put radio buttons on line each set =fieldformat="$e&nbsp;&lt;br&nbsp;/&gt;"= \
%BB% =dropdown= - same as =select= with 1 item visible; use =options= to pass dropdown values \
%BB% =checkbox= - creates a set of checkboxes; to put checkboxes on line each set =fieldformat="$e&nbsp;&lt;br&nbsp;/&gt;"=; use =options= to pass checkbox values \
%BB% =radio= - creates a set of radio buttons; to put radio buttons on line each set =fieldformat="$e&nbsp;&lt;br&nbsp;/&gt;"=; use =options= to pass radio button values \
%BB% =date= - creates a date button; requires !JSCalendarContrib (installed by default) \
%BB% =dateformat= - sets the output format of the date button, for instance: =%Y/%m/%d= - see [[#DateFormats][date formats]] for more info \
%BB% =submit= - creates a submit button \
Expand Down Expand Up @@ -238,8 +238,8 @@ Retrieve the validation status of the form. Note that the status cannot be used

#FormErrors
---+++ FORMERROR
Retreive the current Validation errors - instead of displaying them just above the Form.
* Errors = =%<nop>FORMERROR{"name_of_form"}%= %BR%
Retrieve the current validation errors - instead of displaying them just above the form.
* Errors = =%<nop>FORMERROR{"name_of_form"}%=


---++ Formatting
Expand Down Expand Up @@ -337,13 +337,42 @@ A !FormPlugin form is first processed before it is sent to its action target. Pr

<div class="foswikiImage"><img src="%ATTACHURLPATH%/form_on_submit_diagram.png" alt="" width='804' height='502' /></div>


---+++ Substitution of field references
This allows to use entered field values as variables. For example:
* A form element has the name "To"
* Another form element (for instance a hidden field) has the default value "email response to $To"
* When the form is submitted, =$To= is substituted for the form element value with that name
* The form is passed along


An example form that uses substitution:

<verbatim>
%STARTFORM{
name="mail"
action="view"
topic="%WEB%.%TOPIC%"
method="POST"
}%
%FORMELEMENT{
type="text"
name="To"
}%
%FORMELEMENT{
type="hidden"
name="Subject"
value="email to $To"
mandatory="on"
}%
%FORMELEMENT{
type="submit"
buttonlabel="Submit"
}%
%ENDFORM%

Subject is: %URLPARAM{"Subject"}%
</verbatim>

---+++ Form validation
* Form elements can be checked on input that is nonempty, string, int, float or email
* If a validation error occurs, the form is displayed with error feedback
Expand Down Expand Up @@ -463,11 +492,11 @@ Plugin settings are stored as preferences variables. To reference a plugin setti

---++ Plugin Info

| Copyright: | &copy; Arthur Clemens |
| Copyright: | &copy; Arthur Clemens, Sven Dowideit |
| Other authors: | =Validate.pm=, originally =CGI::Validate= by Zenin <zenin@archive.rhps.org> aka Byron Brummer <byron@omix.com>. Copyright (c) 1997,1998 OMIX, Inc. All rights reserved. Use is granted under the same terms of Perl. |
| Plugin Version: | 20 Jan 2009 (V1.4) |
| Plugin Version: | 20 Jan 2009 (V1.4.1) |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 20 Jan 2009 | 1.4 added sep="", showerrors="" and %<nop>FORMERROR% and fixes for Foswiki v1.0.0 - Foswiki:Main.SvenDowideit |
| 20 Jan 2009 | 1.4 added =sep=""=, =showerrors=""= and =%<nop>FORMERROR%= and fixes for Foswiki v1.0.0 - Foswiki:Main.SvenDowideit |
| 07 Jan 2009 | 1.3 Foswiki release. |
| 08 Mar 2008 | 1.2 Added =condition=, =noformhtml= and =dateformat= attributes. |
| 19 Oct 2007 | 1.1 Added =date= type. |
Expand Down
11 changes: 5 additions & 6 deletions lib/Foswiki/Plugins/FormPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (c) 2007, 2008 by Arthur Clemens
# Copyright (c) 2007, 2008, 2009 Arthur Clemens, Sven Dowideit
# All Rights Reserved. TWiki Contributors
# are listed in the AUTHORS file in the root of this distribution.
# NOTE: Please extend that file, not this notice.
Expand Down Expand Up @@ -36,7 +36,7 @@ use vars
# status of the plugin. It is used by the build automation tools, so
# you should leave it alone.
$VERSION = '$Rev$';
$RELEASE = '1.2';
$RELEASE = '1.4.1';

# Name of this Plugin, only used in this module
$pluginName = 'FormPlugin';
Expand Down Expand Up @@ -572,7 +572,7 @@ sub _displayErrors {
# preserve state information
my $currentUrl = _currentUrl(@_);
$note .=
"$SEP * <a href=\"$currentUrl$anchor\">$fieldName</a> $errorString";
"\n * <a href=\"$currentUrl$anchor\">$fieldName</a> $errorString";
}
return _wrapHtmlError($note) if scalar @sortedErrorFields;
}
Expand Down Expand Up @@ -683,7 +683,7 @@ sub _displayForm {
# multi-part is needed for upload. Why not always use it?
#my $formStart = CGI::start_form(%startFormParameters);
my $formStart = CGI::start_multipart_form(%startFormParameters);
$formStart =~ s/\n/$SEP/eg; #unhappily, CGI::start_multipart_form adds a \n, which will stuff up tables.
$formStart =~ s/\n/$SEP/eg; #unhappily, CGI::start_multipart_form adds a \n, which will stuff up tables.
my $formClassAttr = $formcssclass ? " class=\"$formcssclass\"" : '';
$formStart .= "<div$formClassAttr>$SEP<!--FormPlugin form start-->";

Expand Down Expand Up @@ -928,7 +928,6 @@ sub _getFormElementHtml {
$onMouseOut, $onKeyUp );
my $beforeclick = $params->{'beforeclick'};
if ($beforeclick) {
$value = $beforeclick;
$onFocus = 'foswiki.Form.clearBeforeFocusText(this)';
$onBlur = 'foswiki.Form.restoreBeforeFocusText(this)';

Expand Down Expand Up @@ -1533,7 +1532,7 @@ sub _wrapHtmlError {
my $errorIconImgTag =
'<img src="' . $errorIconUrl . '" alt="" width="16" height="16" />';
return
"#$NOTIFICATION_ANCHOR_NAME$SEP"
"<a name=\"$NOTIFICATION_ANCHOR_NAME\"></a>$SEP"
. '<div id="'
. $ERROR_CSS_CLASS
. '" class="'
Expand Down

0 comments on commit 78c587f

Please sign in to comment.