[Moin-user] forms for moin

Matthew Nuzum newz at bearfruit.org
Mon Sep 18 18:48:00 EDT 2006


I've started writing a parser for moin that will display forms. In
brief, it works like this:

{{{#!form
... form description here ...
}}}

Because of this, it can be embedded in a normal wiki page so it can be
surrounded with other wiki content. The magic is in the form.py
parser. It reads the contents of the form section and uses that to
generate the HTML for the form fields.

I'm hoping to finish this tomorrow (Sept 19th, I'm GMT -5) by the end
of my work day, but I thought I should toss out what I'm doing here in
order to get feedback.

First, here is what it won't do: It will *not* process the form.
instead, either an action needs to be created for the form to be
processed (which I plan to do, but separately) or you need to submit
it to some other cgi/servlet/whatever.

This code is only for displaying the forms.

It works like this, inside the {{{}}} section will be a number of
lines. Each line represents one form field. The form fields will be
shown in the order they are declared. The available form fields are:
 * text (plain text)
 * e-mail (just like plain text, but with validation code)
  * url (again)
 * password - also, the ability to have two password fields that must
match each other
  * text area (multiline plain text) - maybe with the option to turn
it into a wysiwyg, possibly using dojo cf:
http://dojotoolkit.org/docs/rich_text.html
 * section/separator - a heading for logically grouping form elements together
  * select list (option for multi select)
 * check boxes
 * radio buttons
 * hidden field

Each field has in common the following attributes:
 * required = possible values yes/no/true/false/t/f/0/1
  * cssclass
 * id
 * label
 * extra information
 * default value (can be from a cookie, not yet implemented though)
 * name (obviously)
And under consideration
  * onfocus,onchange,etc - this would be disabled by default, and
turned on in wikiconf. If you had a public wiki, untrustworthy users
could put mean javascript there. I'm not sure I'm going to use this,
but I can see how it would be handy
  * adding a captcha field type

Here's the syntax. The first line always describes the form. After
that, anything goes. Each line is a number of columns, separated by
pipes:
field type | options | name | label | default value | sub items |
extra information

Here's an example form:
{{{#!form
form|id=TheRealForm;method=get;cancel=f;submit_text=Click
Me|form1|http://localhost/cgi-bin/submit.cgi
text|required=t|name|Your Name
email|required=t|email|Please enter your e-mail address
subject||subject|Subject|Help Request
textarea|cssclass=wide|msg|Type your message here
section|||Optional Information
select||priority|Priority|3|1=High;3=Medium;5=Low
}}}

Sorry about the wrapping.

I've implemented code like this before in two different systems, one
in PHP, another in XSL.

Each time I implement it, I do it a little better. If you have any
feedback, I'd love to hear it.

-- 
Matthew Nuzum
www.bearfruit.org
newz2000 on freenode




More information about the Moin-user mailing list