RSVPList

Creating an RSVP List - PmForm Example

I run many websites with event pages, and it would be nice to have a cute little RSVP form that will create a list of people who have RSVP'd to an event. Can I do that with PmWiki?

While I would prefer to have a list under each of "yes" "no" and "maybe" PmForm doesn't have that ability yet, so I made a list that could easily be sorted & search-replaced if needed to get a list of RSVPs for event attendance while still looking nice to the webpage visitor. Hopefully this will help if you need to create a PmForm to process data or comments onto the same page as the form.

Summary

  1. Install PmForm (see PmForm Installation instructions)
  2. Define the PmForm reference
  3. Add PmForm template to Site/LocalTemplates
  4. Add PmForm directive to desired page(s)
  5. Save & Test

Define the PmForm reference

Add a line like the one below to your config.php file, after the include line for PmForm:

$PmForm['rsvp'] = 'saveto={$FullName} form=#rsvpform fmt=#rsvppost';

This is a very simple reference: it adds the definition for the "rsvp" PmForm directive to the $PmForm array (i.e. the index in the array will be used in the PmForm directive below). The "saveto" will tell it to save the form data to the current PmWiki page (defined by variable {$FullName}). "form" and "fmt" refer to the PmForm templates created in the next step.

Add PmForm template to Site/LocalTemplates

These templates are explained line-by-line below.

[[#rsvpform]]
(:input pmform target=rsvp :)
(:input default request=1:)
(:input default author "{$Author}" :)
Please RSVP for the event:
(:messages:)
%comment% $[Subject]:      (:input text Subject size=30:)
Name: (:input text author:)
||width=50%
||(:input radio anchor "I'll be there.":) Yes ||(:input radio anchor "I can't make it.":) No ||(:input radio anchor "I might be there.":) Maybe ||
(:input submit post "Submit":)
(:input end:)
[[#rsvpformend]]

[[#rsvppost]]
(:template defaults where=below :)
(:template require author errmsg="$[Missing name]":)
(:template require author match="-*:*,-*@*,-*<*,-*>*" errmsg="Please just enter your name.":)
(:template require Subject match="" errmsg="$[Please leave the subject field blank]" :)
*"{$$anchor}" ~{$$author}
[[#rsvppostend]]

Add PmForm directive to desired page(s)

You must use the (:pmform:) directive with the index used in the $PmForm array.

(:pmform rsvp:)

Save & test


Line-by-Line explanation of the form template

Start the form template definition

[[#rsvpform]]

The name for this anchor is defined in the $PmForm array definition in your config.php file.

Define the form type and the PmForm index

(:input pmform target=rsvp :)

Uses the same $PmForm array index used in your config.php file.

Give the form an OK to use previously submitted data

(:input default request=1:)

If the user makes an error and needs to resubmit, the form will refill with previously submitted information.

Use the current Author's name

(:input default author "{$Author}" :)

Elegant in case they're logged in or have already edited a page on the site and filled in the Author field, or if they've already RSVP'd for an event on another page.

Start the visible portion of the form

Please RSVP for the event:

Make form messages visible

(:messages:)

Will be replaced with form processing directives, defined below or produced by the PmWiki internal form processing or PmForm system. You may want to wrap this line with styling to make the error messages more visible:

>>red<<
(:messages:)
>><<

You can also style form messages using CSS.

Add a honeypot form field

%comment% $[Subject]:      (:input text Subject size=30:)

This is a diversionary tactic to detect spam. The theory is that automated spam applications (spambots) would presume this is an email form and fill this form in with some type of text. It is hidden with CSS () so that most people will not see it. One exception is that some screen readers or accessibility software may not respect the "hidden" CSS quality. So later we check whether there is text in the field and send a message to the browser reminding the person that Subject should be left blank. A spambot would not stick around or would not understand the message, so the spambot wouldn't get through. A human using a screen reader would get the message and change the subject line. This does not stop human spam robots (people paid to spam forms). For more information see HoneyPot.

Continue with normal form fields

Name: (:input text author:)
||width=50%
||(:input radio anchor "I'll be there.":) Yes ||(:input radio anchor "I can't make it.":) No ||(:input radio anchor "I might be there.":) Maybe ||
(:input submit post "Submit":)

End the PmForm template definition

(:input end:)
[[#rsvpformend]]

The first line ends the

. The second line ends the actual form template definition.

Line-by-Line explanation of the post template

Begin the post template

[[#rsvppost]]

Define the location for the posted data

(:template defaults where=below :)

Since we're posting the data on the same page, we need to say where we want the data posted. In this case, the data will be posted below the RSVP form. It can be posted above the form, or at the top or bottom of the page content in question. It will actually insert the data into the page text and you can edit the data along with editing the wiki page.

Data checking & form validation

Is there a "name" for this "author"?

(:template require author errmsg="$[Missing name]":)

Is the author name valid (form security)

(:template require author match="-*:*,-*@*,-*<*,-*>*" errmsg="Please just enter your name.":)

This will check that the author name field isn't being misused. This is a comma-separated list. The hyphen (minus sign) is used to define items NOT allowed. The asterisk is a wildcard (any number of characters). Thus this line prevents any entries containing : @ < or >. Preventing the : prevents any external links and linked phone numbers on mobile devices. Preventing the @ symbol will prevent email addresses. Preventing < and > will help detect if someone is attempting to add HTML or PHP code to the form in an attempt to break into the site.

If you also want to prevent internal links to other pages on the wiki you will want to add -*[* to the list. If you want to prevent someone adding a link to their profile page, eliminate the ~ character.

Check the honeypot

(:template require Subject match="" errmsg="$[Please leave the subject field blank]" :)

Requiring a blank field means that the error message will go to the screen if there's anything entered into the field.

Write to the page

*"{$$anchor}" ~{$$author}

I am making a bulleted list that passes along the canned message (i.e. "I'll be there." for a yes RSVP) followed by a tilde (~) and the name of the person who RSVP'd.

End the template

[[#rsvppostend]]

Options

Text Length Limit

You can increase security by limiting the number of characters allowed in the Name field (say to 140 characters?) by using PmForm plus the http://www.pmwiki.org/wiki/Cookbook/ConditionalExtensions recipe:

(:template require author if="le {(strlen '{$$author}')} 140" errmsg="You are only allowed 140 characters.":)

The Conditional Extensions recipe is needed for the le conditional markup ("less than or equal to"). The markup expression {(strlen '{$$author}')} is built into PmWiki.

A Proper Bullet List

As noted in PmForm.DataForms#Issues, if you want a bullet list without spaces between the lines, you have to trim out excess linebreaks before the output line(s).


Contributors

XES May 27, 2014, at 08:37 AM

 0: 00.00 00.00 config start
 1: 00.01 config end
 2: 00.21 MarkupToHTML begin
 3: 00.25 ReadApprovedUrls SiteAdmin.ApprovedUrls begin
 4: 00.26 ReadApprovedUrls SiteAdmin.ApprovedUrls end
 5: 00.26 MarkupToHTML end
 6: 00.26 MarkupToHTML begin
 7: 00.28 MarkupToHTML end
 8: 00.28 MarkupToHTML begin
 9: 00.28 MarkupToHTML end
10: 00.28 now