XQuery/Basic Feedback Form

Motivation

edit

You want to gather feedback from visitors.

Implementation

edit

A simple HTML form gathers suggested improvements and an email address. The suggestion is emailed to one of the authors and an acknowledgment sent to the submitter. Here the default send-mail client on the eXist implementation at UWE, Bristol is used.

XQuery script

edit
xquery version "1.0";
 
(: A simple Feedback form using the eXist mail module :)
 
import module namespace mail="http://exist-db.org/xquery/mail";
declare option exist:serialize "method=xhtml media-type=text/html";

let $comment:= normalize-space(request:get-parameter("comment",""))
let $email := normalize-space(request:get-parameter("email",""))
return 
<html>
  <head>
    <title>Feedback on the XQuery Wikibook</title>
  </head>
  <body>
   <h1>Feedback on the XQuery Wikibook</h1>
   <form method="post">
     Please let us know how this Wikibook could be improved.<br/>
     <textarea name="comment" rows="5" cols="80"/><br/>
     Your email address <input type="text" name="email" size="60"/>
     <input type="submit" value="Send"/>
  </form>
  {if ($email ne "" and $comment ne "")
  then 
      let $commentMessage :=
  <mail>
    <from>{$email}</from>
    <to>kit.wallace@gmail.com</to>
    <subject>Wikibook Feedback</subject>
    <message>
      <text>{$comment}</text>
    </message>
  </mail>
      let $ackMessage := 
   <mail>
    <to>{$email}</to>
    <from>kit.wallace@gmail.com</from>
    <subject>Wikibook Feedback</subject>
    <message>
      <text>Many thanks for your feedback - we appreciate your interest in this collaborative work.</text>
    </message>
  </mail>
     let $sendcomment := mail:send-email($commentMessage,(),())
     let $sendack := mail:send-email($ackMessage,(),())
     return
       if ($sendcomment and $sendack)
       then 
         <div>
           <h2>Feedback</h2>
           <p>You suggested that the XQuery Wikibook could be improved by:<br/>
           <em>{$comment}</em>.  
           <br/>Thanks for the feedback.</p>
         </div>
       else 
         <p>Something went wrong - please try again</p>
    else
    if ($comment ne "")
    then <div>Please provide an email address so that we can let you know of progress on your suggestion.</div>
    else 
    ()
    }
  </body>
</html>

Feedback Form