[pmwiki-users] Validating and appending data from Forms and Displaying

Peter & Melodye Bowers pbowers at pobox.com
Fri Mar 21 16:47:46 CDT 2008


> I would like to create a sign-up sheet for an event. Before moving to
> PmWiki I used a perl script for this form with a simple csv file
> containing all the allowed emails. I simply recorded the registered
> emails in another csv file and dynamically generated a page listing
> those registered.
> 
> I would like to recreate this system within PmWiki.

Here's how it would look with WikiSh:

===(snip the-page-with-the-form)===
{(wikish_form QUICKFORM PROCESS)}
(:input text name=address:)
(:input submit name=b value="Sign Up":)
(:linebreaks:)
{(wikish source WikiSh.Validate#A)}
===(snip)===

That's the entire form -- the QUICKFORM argument is a shorthand for the rest
of the input directives.

The validation script has been put in WikiSh.Validate#A just for
readability.  It could have been placed in the form itself as well, but
since MarkupExpressions don't support multi-lines it is kind of hard to read
- the following line would substitute for the {(wikish source ...)} line:

{(wikish if test -n ${address}; then; if test ${address} ~=
/^[a-zA-Z]\w*@[\w.]*$/; then; echo "Yep, got a match"; if grep -q
"^${address}$" WikiSh.Attendees; then; echo "You are already signed up";
else; if grep -q "^${address}$" WikiSh.MemberAddresses; then; echo
${address} >>WikiSh.Attendees; echo "You are now on the list."; else; echo
"Sorry, you are not a member."; fi; fi; else; echo "No, that does not look
like an email address"; fi; fi;)}

Since that is headache-inducing to read in a single line, the original form
above sources the script from a different page in multi-line form and that
section from that page follows:

===(snip WikiSh.Validate)===
[[#A]]
if test -n ${address} # if there's no value then don't bother giving any
messages
then
   if test ${address} ~= /^[a-zA-Z]\w*@[\w.]*$/
   then
      echo "Yep, looks like an email address"
      if grep -q "^${address}$" WikiSh.Attendees
      then
         echo "You are already signed up"
      else
         if grep -q "^${address}$" WikiSh.MemberAddresses
         then
            echo ${address} >>WikiSh.Attendees   # Here the address is
actually added
            echo "You are now on the list."
         else
            echo "Sorry, you are not a member."
         fi
      fi
   else
      echo "No, that does not look like an email address"
   fi
fi;
[[#ENDA]]
===(snip)===

Hope that helps.

-Peter

PS Make sure you've got an updated version of WikiSh as getting code from an
anchored section within a page is something just implemented.




More information about the pmwiki-users mailing list