|
Cookbook /
WikiFormsSummary: Use a form template to create, edit and list wiki pages
Version: 1.0.71 (2009-01-11)
Status: Stable
Prerequisites: pmwiki 2.0 and above; 2.1 recommended; works fine with 2.2
Maintainer: jr
Categories: Forms
<< Input | Forms-related | >> GoalsProvide a mechanism for forms-based entry and updating of structured wiki pages. Uses include:
Make the form template a wiki page, so you can set up new forms for new purposes. Use the form to create new pages and edit existing pages. Information is stored on the basis 1 issue = 1 page. For appending issues to existing pages, use a different recipe like CommentBox (for example). The script automatically adds form links to the template page, to create a new page, and to each issues page (ie those with names of 5 digits), to edit the page. (see CompareFormsRecipes) Solutionwikiform.phpΔ and wikiform-i18n-en.phpΔ -- this is now mature and stable. Use the WikiFormSample to get a quick-start on a template. WikiFormCSS.phpΔ is a sample style script. There is a working, live example of an issues register for a real project and a tips register for how-to tips. These both contain real data; at the moment there isn't a "playground" for people to experiment.
Those people who want to take advantage of the page title options and refer to a form-generated page by its title also need to install formtitle.phpΔ (updated 2009-01-11). Internationalised versions:
(Please note. The PublishPDF library includes the WikiForms recipe.) InstallationTo enable the wikiform capability, download the scripts wikiform.phpΔ and wikiform-i18n-en.phpΔ and install them in the cookbook/ directory. Then add the following line to your local/config.php file: include_once("cookbook/wikiform.php");
You also need to download and install the MarkupExtensions, if you haven't already done so. To use the form styles, download the WikiFormCSS.phpΔ script, put it in your local/ directory and rename it to the name of the group which contains the form-based pages. Configuration OptionsBy default, the "Edit Form" link is at the bottom of the page. To move it to the top of the page, add the following line before the include wikiform.php line in config.php: $FormNavFooter= false; History
ContributorDiscussionTo set up a new form, create a template page. The script looks for
The form template name is defined in $FormTemplatePage (default value = 'FormTemplate'). The forms group name is defined in $FormsGroup (default value = 'Forms'). It turns out that it's important that the $FormTemplatePage and $FormsGroup declarations are placed before the include_once("cookbook/wikiform.php"); statement. -- Patrick Linskey March 30, 2005, at 12:00 AM
There are 2 directives: (:wikiform:) generates a form
(:wikilist name=value:) lists pages where 'name' matches 'value'
(:wikilist group=GroupName:) lists pages from the GroupName group
(if the value includes spaces, write name='some value') The script generates the form from any :<prompt text>:<variable> <tool tip text> <field type> <sort> <sum>
For example, with all options set: :Urgency:urgency do we need to solve this now or later? (1|1 - later;2;*3;4;5|5 - now) - 0+
Taking each piece in turn...
Avoid the use of underscores or dashes in variable names - letters only, please. --PeterBowers October 22, 2007
Avoid the use of uppercase letters in variable names - lowercase alpha only, please. --PeterBowers November 6, 2007
Avoid the use of parentheses, + or - or * characters. --PeterBowers May 16, 2008, at 01:24 PM
Field types supportedThe following values for <field type> are supported.
:Summary:summary ("If you think education's expensive, try ignorance")
:Summary:summary ("If you think education's expensive, try ignorance"=55)
Note: Using (title) can mess up the form if wikiforms is used alongside other Pmwiki cookbooks which also use (title). I found other scripts were confusing this directive so multiple (titles) would appear when editing a saved form. You should aim to test entries by editing them to see if all looks ok and if not to comment out other cookbooks in your config to see which is causing the conflict. A good way to see if your edits are good is to view the source ?action=source. With thanks to jr --david
Any field can have a comment displayed in the resulting form, e.g. as help text. In the form template, start the line after the field definition with :: followed by the comment text. At this time, the comment may not contain wiki markup -- plain text only. (NOTE: Avoid colons in this comment text after the initial double-colon. They mess up your form big-time. --PeterBowers)
(Now fixed --jr)
Sorting columns in the list viewThe list directive lets you click on any column heading to sort the selected pages based on that column. After the resorted list displays, clicking the column heading again reverses the sort order. <sort> matches the pattern "[-+]\\*?" -- a plus sign or a minus sign followed by an optional asterix. A plus sign denotes include this item and sort in ascending order; a minus sign denotes include this item and sort in descending order. An asterix denotes include this field in the default sort order. The script adds the page name to the end of the list of default sort fields. :Fee:fee + :Fie:fie :Foe:foe +* :Foo:foo :Bar:bar -* The To sort by the date of the last modfication of each page, you need to specify +*lastmodified or -*lastmodified in your wikilist directive, for ascending or descending sort order respectively. Because it sorts left to right and the last modified date is the right hand field, you need to disable the default sort order for all other columns. Assigning a score to a pageSuppose we are setting up a risk register. Each risk has the components of likelihood that it will happen and impact if it does happen. We want to monitor high likelihood, high impact risks. We would use the <sum> option, which matches "\d[-+]" -- a digit followed by a plus sign or a minus sign. For example: :Risk:risk :Likelihood:likelihood (1;2;3;4;5) 0+ :Impact:impact (1;2;3;4;5) 1+ This will generate 2 sets of radio buttons and add a Score column to the score = + (likelihood -0) + (impact -1) Using \d- now works. Why do we need this? Suppose we are carrying out an end of project review. We might set up: :Benefit area:benefit :Benefit potential:potential (1;2;3;4;5) 0+ :Benefit achieved:achieved (1;2;3;4;5) 5- We want to look for areas of high potential benefit and low achievement, to take remedial action. The score values range from 09 (high potential, low achievement) to 01 (low potential, high achievement). The sort works on positive numbers, so we have to shift the second number up by 5: score = + (potential - 0) - (achieved - 5) Changing default field sizesThe designer has some control over the field sizes. The following options for selected <field type> are supported.
(:wikilist:) optionsBy default, the list uses the columns specified in the template. But an author can create custom lists that override this. For example: (:wikilist !category:) omits the category element from the list
(:wikilist +priority:) adds the priority element, sorted ascending
(:wikilist -urgency:) adds the urgency element, sorted descending
To include a new element in the default sort, add an asterisk; for example: (:wikilist +*priority:) adds the priority element, ascending and included To include the page's last modified date (ensure that there is not a form field called 'lastmodified'), write (:wikilist +lastmodified:) Element settings in wikilist override the template settings. If the wikilist includes a name=value option, the selection works whether or not the named element is one of the output columns. "page" is a special element. It is not a field but rather for setting an option for what will happen when you click on the page links. To turn the page browse links into links to the edit form view (i.e., edit as a normal wikipage being edited - no wikiforms functionality), enter (:wikilist page=edit:) To turn the page browse links into links to the standard form view (i.e., the wikiforms form from FormTemplate), enter (:wikilist page=form:) Note that this setting alters the NUMERIC page links, not the TITLE page links if you are using the formtitle.php addon. Template options (new feature)Sometimes, a site wants to use the same template for multiple groups. Here's how. Suppose there is a need for multiple Risks registers, all using the same risk form template.
Inter-group linksThis describes a projects and tasks application -- many projects, each can have many tasks, but each task is associated with only one project. Sometimes, a site wants to create a 1-to-many relationship between pages in one group (GroupA) and pages in another, forms-controlled group (GroupB). Suppose the form entry page is GroupB.NewPage:
Of course, GroupA can also be a forms-controlled group. In relational terms, this is GroupA---keyfield--<GroupB where keyfield is the name of the entry in GroupA and appears as a foreign key in GroupB. IssuesIt currently requires installation of MarkupExtensions, as it makes use of => right alignment markup. See the modified Messages are in English. These are now in an wikiform-i18n-en.phpΔ file. Markup to define fields may change. It could be simplified. What do we do about wiki tables? It would be useful if this could support table editing. What do we do about vote fields? These could be simple (votes = for - against) or complex (strongly for, for, against, strongly against). For example, the page might look like this:
The form view would let an author vote for or against via a radio button. If we support strongly for and against, such votes might count double. List Selection CriteriaThe = operator matches partial strings ("contains"), so markup of the type It is possible to use markup like It is also possible to use 'or' logic, for example Combining selections with a space implies "and". So The space and vertical-bar "operators" combine as expected: The == operator requires an exact match rather than a "contains." (Like a pattern anchored at beginning and end.) Note that if you use quotes around your query value then the second "=" must be INSIDE the quotes with this syntax: Sort orderClick a column once and it sorts according to the template. Click it again and it reverses the sort order. Immediate SaveYou can force the forms recipe to save the page when you press 'Submit'. Add the following line to local/config.php above the line that includes wikiform.php: $WikiFormSubmit = 'post'; ## or 'postedit' Field comment textTo add comment text to a form, use ::definition text, like this: ::comment will appear below the form field At the moment, it does not recognise wiki markup in such comments. (NOTE: Avoid colons in this comment text after the initial double-colon. They mess up your form big-time. --PeterBowers)
Dividing the form into groups of fieldsUse heading markup. The first heading will be the overall page heading. Subsequent headings are treated as <th> tags in the table of form fields. Use of this feature makes long forms more usable. More on the overall inner workings of WikiFormsHere is more info on how to setup WikiForms. Bugs and Feature Requests(I have tried to organize the numerous comments on this recipe in a useful fasion and separate them from the "bare bones" of the documentation. I hope that makes everything easier to read and a bit more user- (and author-)friendly :-) --Henning August 23, 2006, at 09:35 AM)
User notes: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date * (-) Optional negative comment. Name, date These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |