JSPWiki now (2.1.127+) includes the WikiFormsPlugin that allow simple html forms to be created on wiki pages. When the form is submitted the values are passed as parameters to a user defined 'handler' plugin which is invoked when the form is submitted.

This is actually a set of interrelated plugins, not just one.


First you start with...
  • FormSet - sets default form element values.
  • FormOutput - calls the designated handler and displays its output.
  • FormOpen - starts the form by emitting the html <form> tag.

Then you put any normal wikitext between the FormOpen and FormClose along with any number of the following form elements.

Finally you must end your form with...

  • FormClose - ends the form by emitting the html </form> tag.

And that's it, if you want you can define any number of forms on one page, just don't nest their FormOpen/FormClose portions. When a form submit button is hit by the user the input/select/textarea elements are sent to the server where the handler gets invoked and the values are available as it's parameters.

The following example uses the form plugins to provide parameters to the CurrentTimePlugin, and displays the result.


The FormSet plugin sets the default date format for a form field format in form testform. This is hidden in normal WikiPage viewing, looks like this:
[{FormSet form='testForm' format='EEE, d MMM yyyy mm:ss:HH Z'}]


FormOutput specifies that the 'handler' (here, the CurrentTimePlugin), should be used to generate some output to display here. While the output is usually built in response to a POST from a form called testform, the populate attribute here hints that we want default information shown (the plugin called) even if no post has yet been made.
[{FormOutput form='testForm' handler='CurrentTimePlugin' populate='handler'}]
Thu, 9 Feb 2023 14:51:05 +0200


The third element starts the actual HTML form called testform, there is no visible output from this.
[{FormOpen form='testform'}]


Text fields#

We'll use a text field to provide the format of CurrentTimePlugin's output. Notice that the name of this field is format - the name of CurrentTimePlugin's relevant parameter. This value is passed straight to CurrentTimePlugin on submit:
[{FormInput type='text' name='format'}]
Enter the time format string:

With default value:

[{FormInput type='text' name='name' value='value'}]

The rest of this form merely demonstrates the other HTML form elements. They don't mean anything to the CurrentTimePlugin of course, but just for fun here's what they look like.


[{FormInput type='checkbox' name='orderSpam' value='spam'}] Spam!\\
[{FormInput type='checkbox' name='orderParrot' value='parrot'}] Dead parrot.\\
[{FormInput type='checkbox' name='orderLumber' value='lumber'}] Lumberjack.\\
Dead parrot.

Radio buttons#

Notice that all radio button elements share the same name, that's how you can 'group' them if you want multiple sets.

You can set the default checked item using checked='on|true|yes'. (In versions past 2.2.33 the value may also include the XHTML value of 'checked'.)

[{FormInput type='radio' name='favoriteActor' value='jones'}] Terry Jones
[{FormInput type='radio' name='favoriteActor' value='chapman' checked='true'}] Graham Chapman
[{FormInput type='radio' name='favoriteActor' value='cleese'}] John Cleese
[{FormInput type='radio' name='favoriteActor' value='idle'}] Eric Idle
[{FormInput type='radio' name='favoriteActor' value='gilliam'}] Terry Gilliam
[{FormInput type='radio' name='favoriteActor' value='palin'}] Michael Palin
Terry Jones
Graham Chapman
John Cleese
Eric Idle
Terry Gilliam
Michael Palin

Submit buttons #

What good is a form if there isn't any way to submit it? You can of course put multiple submit buttons, each for differing actions the name parameter will be a key in the parameter Map passed to the plugin. The plugin can look for various keys to tell which button was used to do the form submission.
[{FormInput type='submit' name='updateButton' value='Update Button'}]
[{FormInput type='submit' name='differentButton' value='A Different Button'}]


This allows you to define a drop-down selection list. Notice, the asterisk; this denotes the default value to be selected when displayed. The separator character (;) and the default character (*) can be overridden - check the JavaDocs of this plugin.
[{FormSelect name='breakfast' value='egg and spam;egg bacon and spam;*egg bacon sausage 
and spam;spam bacon sausage and spam;spam egg spam spam bacon and spam;'}]


Of course what good is a form without the abiltiy to have a multiline text area.

Please tell us why you like Monty Python

[{FormTextarea name='whyIlikeMontyPython' rows=5 cols=40}]


And, finally, an invisible closing element to denote that this form has ended:

What happens on submit?#

When you click on a submit button, the form is posted to the current page. All the Form inputs specified on the page are given to the WikiPlugin defined in the FormOpen invocation's handler parameter. The plugin receives the inputs in a Map of input name-value pairs (just like WikiPlugins always do), performs whatever logic it needs to do, and optionally provides output (see FormOutput). It may also adjust the submitted values.

The form is then redisplayed, with the submitted values (except where adjusted by the handler).

Hope this helps. These plugins are availble as part of the 2.1.127+ version of JSPWiki. Enjoy your spam.

Can I set a value in handler for a input box and display it on the next page? -- GerryLau
I found the answer. Need to pay attention to the order of FormOutput and FormSet. Otherwise your value set in FormOutput will be overwritten by the coming FormSet.


I wrote a plugin which processes a form. The problem that i would like to display the result on a new page coming up immediately after submit. I see some solution that saves a new page and gives back a link to the newly created page. But I don't want to store pages, but dynamically generate them.

Any idea? Gergo

--GergelyGulis, 28-Oct-2006


Could I get the form to pass the input values to a external server, some where else on the web, or will it only send data to a local plugin?

Barry Beveridge, 11-Jan-2007

Barry, HTML forms have an action attribute that contain any valid URL, but we don't really want people to have the freedom to be returning the content of processed forms to anywhere on the net from a user-edited page simply for security reasons, e.g., someone might fill out a form with private information thinking it's going one place but it's really getting sent somewhere else. Now, if you're a wiki site administrator and want form content sent somewhere else, you can write a plugin handler to receive the form content, then have that handler do the dirty work. This keeps the security intact and allows you to process the output in whatever way you like (and also maintain security in whatever way you like since the handler is within your control).

For example, I've been playing with XML-RPC recently, and it's feasible to have the form handler plugin send its content via XML-RPC to another wiki site, or any other that could receive the XML-RPC transmission. This of course is just one possible approach (with other "web services" possible too), but the way to do this is with your own custom handler.

-- MurrayAltheim, 12-Jan-2007

I don't understand how the form is processed. I want to create some kind of issuetracker, kind of like the NewIdea tracker. I've adjusted the FormOutput example, but I get the message "Cannot instantiate plugin FormHandler". I'm using version 2.5.18.

  1. When submitting a form, does this mean that automatically a page is created?
  2. How can I specify the name of the page from field names?
  3. What kind of handlers are there, which one should I use?
  4. In the bugreport form I see the bugreporthandler, and another parameter populate='handler'. Is this populate parameter specific to this handler? What other parametes are there?
  5. I want to create a link to the issuetracker in the new page automatically. I suppose I can do this using a form element value.
  6. Is it possible to use hidden elements?

--RvW, 08-Feb-2007 ---


Looks like you are using a FormHandler from the example. You either need to use the handlers from out-of-box JSPWiki distribution or write your own. If you are writing your own you need to install:

Refer to Installing Plugins page.

Though this was raised long back, still answering for others' benefit & create a knowledge base.

--YogeshN, 06/13/2008

I would like to get a complete list and explanation of ALL the syntax that the Wiki Forms Plugin uses. Can anyone help me?

--Bill Robfogel, 06-Apr-2007

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
534870_mikkel_1.jpg 9.8 kB 1 08-Aug-2007 10:54
« This page (revision-50) was last changed on 30-Nov-2011 10:17 by