Skip to content

Commit

Permalink
Item9056: numerous fixes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/FormPlugin@7528 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed May 24, 2010
1 parent 4da32e1 commit 81976f7
Show file tree
Hide file tree
Showing 9 changed files with 1,323 additions and 510 deletions.
51 changes: 24 additions & 27 deletions data/Sandbox/FormPluginExamples.txt
Expand Up @@ -38,21 +38,17 @@ default="mary,peter"
validate="nonempty"
fieldformat="$e <br />"
mandatory="on"
hint="Select any person"
hint="Select at least one person"
}%
%FORMELEMENT{
name="And_even_more_persons"
type="selectmulti"
title="And even more persons without custom =fieldformat=:"
options="mary, peter, annabel, nicky, jennifer"
labels="Mary M, Peter P, Annabel A, Nicky N, Jennifer J"
value="mary,annabel"
size="5"
validate="nonempty"
mandatory="on"
hint="Select any person"
title="Multiselect is =selectmulti=:"
name="subject"
options="work,freetime,not important"
labels="Work, Freetime, Not important"
default="not important"
size="3"
}%
%FORMELEMENT{type="selectmulti" title="Multiselect is =selectmulti=:" name="subject" options="work,freetime,not important" labels="Work, Freetime, Not important" default="not important" size="3"}%
%ENDFORM%


Expand All @@ -67,7 +63,7 @@ action="view"
name="Name"
type="text"
disabled="on"
title="Enter your name:"
title="Your name:"
default="%WIKIUSERNAME%"
}%
%FORMELEMENT{
Expand Down Expand Up @@ -99,7 +95,7 @@ action="view"
name="Name"
type="text"
readonly="on"
title="Enter your name:"
title="Your name:"
default="%WIKIUSERNAME%"
}%
%FORMELEMENT{
Expand Down Expand Up @@ -166,17 +162,17 @@ anchor="ResultUrlParam"
%FORMELEMENT{
name="MyName"
type="text"
title="Enter your name:"
title="Your name:"
mandatory="on"
value="Adam"
}%
%FORMELEMENT{
name="MyOptions"
name="MyFriends"
type="checkbox"
title="Choose option:"
mandatory="on"
options="1,2,3"
value="2"
options="alex,barbara,cynthia"
default="barbara"
}%
%FORMELEMENT{
name="action"
Expand All @@ -185,9 +181,10 @@ buttonlabel="Submit"
}%
%ENDFORM%

Submit form to view values:
#ResultUrlParam
* Name = %URLPARAM{"MyName"}%
* Options = %URLPARAM{"MyOptions"}%
* Friends = %URLPARAM{"MyFriends" multiple="on" separator=", "}%


---++ Formatting forms
Expand All @@ -198,9 +195,9 @@ name="hintform"
action="view"
}%
%FORMELEMENT{
name="Name"
name="Your name"
type="text"
title="Enter your name:"
title="Your name:"
mandatory="on"
hint="Or just anything"
}%
Expand Down Expand Up @@ -230,7 +227,7 @@ elementformat=" $t $e $m $h "
}%%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
}%%FORMELEMENT{
name="action"
type="submit"
Expand All @@ -257,7 +254,7 @@ elementcssclass="foswikiFormStep"
%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
}%
%FORMELEMENT{
name="action"
Expand All @@ -277,7 +274,7 @@ action="view"
%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
cssclass="foswikiBroadcastMessage"
}%
%FORMELEMENT{
Expand Down Expand Up @@ -320,7 +317,7 @@ action="view"
name="Name"
type="text"
focus="on"
title="Enter your name:"
title="Your name:"
}%
%ENDFORM%
</verbatim>
Expand Down Expand Up @@ -493,7 +490,7 @@ elementcssclass="foswikiFormStep"
%FORMELEMENT{
name="Your name"
type="text"
title="Enter your name:"
title="Your name:"
default=""
mandatory="on"
validate="nonempty"
Expand Down Expand Up @@ -549,13 +546,13 @@ topic="%WEB%.FormPluginExamplesFeedback"
%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
mandatory="on"
}%
%FORMELEMENT{
name="Salary"
type="text"
title="Enter your salary:"
title="Your salary:"
mandatory="on"
validate="float"
}%
Expand Down
15 changes: 12 additions & 3 deletions data/Sandbox/FormPluginExamplesFeedback.txt
@@ -1,6 +1,15 @@
%META:TOPICINFO{author="BaseUserMapping_333" comment="reprev" date="1274078706" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="FormPluginExamples"}%
#CarbonCopy
%URLPARAM{"CarbonCopy"}%
---++ Result of carbon copy
Value of =<nop>CarbonCopy=: %URLPARAM{"CarbonCopy"}%

#FormValidation
%URLPARAM{"Your name"}% %URLPARAM{"Your salary"}% %URLPARAM{"Checkname"}%

---++ Result of form validation
* Value of =Your name=: %URLPARAM{"Your name"}%
* Value of =Your salary=: %URLPARAM{"Your salary"}%
* Value of =Checkname=: %URLPARAM{"Checkname"}%

* friends = %URLPARAM{"friends" multiple="on" separator=", "}%
* subject = %URLPARAM{"subject" multiple="on" separator=", "}%
* friends = %URLPARAM{"friends" multiple="on" separator=", "}%
88 changes: 14 additions & 74 deletions data/System/FormPlugin.txt
Expand Up @@ -31,7 +31,7 @@ action="view"
%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
mandatory="on"
}%
%FORMELEMENT{
Expand All @@ -52,7 +52,7 @@ action="view"
%FORMELEMENT{
name="Name"
type="text"
title="Enter your name:"
title="Your name:"
mandatory="on"
}%
%FORMELEMENT{
Expand Down Expand Up @@ -152,7 +152,7 @@ In case of an error, the default notification anchor link is used to directly po
| =elementcssclass= | The CSS class of the element container. Use CSS class =foswikiFormStep= class to divide the form in steps. |=-=|=-=| =elementcssclass="foswikiFormStep"= |
| =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= | 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"= |
| =showerrors= | Position of the error feedback: =above= the form (default), =below=, or =off= (hide). Use =%<nop>FORMERROR%= to display the message elsewhere. |=-=| ="above"= | =showerrors="off"= |
| =noredirect= | By setting this to "on", !FormPlugin will not redirect after submitting a form (after validation failure or success). |=-=|=-=| =noredirect="on"= |

---+++ FORMELEMENT
Expand Down Expand Up @@ -361,6 +361,13 @@ Retrieve the current validation errors - instead of displaying them just above t
* Errors = =%<nop>FORMERROR{"name_of_form"}%=


---++ Retrieving form values
Use [[%SYSTEMWEB%.VarURLPARAM][%<nop>URLPARAM{}%]] to display submitted form values. For example
<verbatim>
* Name = %URLPARAM{"MyName"}%
* Names = %URLPARAM{"MyFriends" multiple="on" separator=", "}%
</verbatim>

---++ Formatting
Formatting of each form element can be set with the =FORMELEMENT= parameters:
* =format= - defines the display of:
Expand Down Expand Up @@ -504,57 +511,6 @@ Use =%<nop>FORMSTATUS{}%= to retrieve the status of the form; see [[#FormStatus]
See [[Sandbox.FormPluginExamples]]


---+++ Upload form
An upload form to attach a file to a topic should contain these parameters:
* STARTFORM param =action="upload"=
* STARTFORM param =topic= and =web=, or use the more compact =topic="Web.TopicName"= format
* STARTFORM param =method="POST"=
* STARTFORM param =validate="off"= - form validation does not work with file upload
* FORMELEMENT param =name="filepath"=

Example:
<verbatim>
%STARTFORM{
name="uploadform"
action="upload"
topic="%WEB%.%TOPIC%"
method="post"
validate="off"
}%
%FORMELEMENT{
type="upload"
name="filepath"
title="Attach new file"
size="70"
}%
%FORMELEMENT{
type="submit"
buttonlabel="Upload file"
}%
%ENDFORM%
</verbatim>

Optionally additional attachment parameters can be set with these fields:
<verbatim>
%FORMELEMENT{
name="filecomment"
type="text"
title="Comment"
}%
%FORMELEMENT{
name="hidefile"
type="checkbox"
options="on=Do not show attachment in table"
}%
%FORMELEMENT{
name="createlink"
type="checkbox"
options="on=Create a link to the attached file"
}%
</verbatim>

See the working example in [[Sandbox.FormPluginExamples#Upload][FormPluginExamples:Upload]]


#PluginSettings
---++ Plugin Settings
Expand Down Expand Up @@ -588,26 +544,9 @@ Plugin settings are stored as preferences variables. To reference a plugin setti



---++ Further development
* The form validation does not work correctly with multiple forms on one page and when the method is POST
* It would be nice to feed form values from other topics
* It would be nice if the form had javascript form validation as well to provide direct user feedback.



---++ Plugin Installation Instructions

*Note:* You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where Foswiki is running.

* Download the ZIP file from the Plugin web (see below)
* Unzip ==%TOPIC%.zip== in your installation directory. Content:
| *File:* | *Description:* |
| ==data/System/FormPlugin.txt== | Plugin topic |
| ==data/Sandbox/FormPluginExamples.txt== | Working examples |
| ==lib/Foswiki/Plugins/FormPlugin.pm== | Plugin Perl module |
| ==lib/Foswiki/Plugins/FormPlugin/Validate.pm== | Plugin Perl module for form validation |
| ==pub/System/FormPlugin/formplugin.css== | Style Sheet |
| ==pub/System/FormPlugin/error.gif== | Error icon |
---++ Installation
%$INSTALL_INSTRUCTIONS%



Expand All @@ -618,13 +557,14 @@ Plugin settings are stored as preferences variables. To reference a plugin setti
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 16 May 2010 | 1.6 Arthur Clemens: %BR%\
| 24 May 2010 | 1.6 Arthur Clemens: %BR%\
Bug fixes: \
%BB% Fixed pre-selecting multiple items in multi-select form elements. \
%BB% All Foswiki scripts are now allowed in =action=. \
%BB% Fixed redirecting a topic and passing data in GET instead of POST (added =passthrough= parameter). %BR%%BR%\
More: %BR%\
Complete unit testing. %BR% \
Messages are now set in template =formplugin.tmpl=, making them easier to change. %BR% \
Improved documentation. |
| 24 Aug 2009 | 1.5 Arthur Clemens: %BR%\
Bug fixes: \
Expand Down

0 comments on commit 81976f7

Please sign in to comment.