MailPost -- Guestbook example

MailPost can save the results of a form submission in just about any format you want by using a template file. In this example, MailPost will save the information in a way that allows you to create a guestbook for your website.

The following actions were taken to produce the result:

  1. Create the form and insert the success variable. In this example, we are going to use a URL as our success page, which is the same file that we are using as our X-SaveAs filename, my-book.html . We're using a URL instead of a file for the success page because guestbooks can be rather big files. MailPost has a 32KB limit. By using a URL, this limit will not be invoked.
     
  2. Create the form's template file that will be used with this form. This example's template file is named tmpl-1.txt
    To:
    From: mailpost@mcenter.com
    Subject: Guestbook test
    X-SaveAs: my-book.html
    X-SaveUsing: guestbook.txt
    
      This is a test of creating a Guestbook.

    Note that the "To:" header is left blank. This instructs MailPost not to send an email message. The X-SaveAs: header contains the filename to save the results to. For this example, this file will be my-book.html . Notice we are writing directly to an HTML file and this file is the success page that will display in the browser. The X-SaveUsing: header contains the name of the template file (guestbook.txt) to use to format the file. All file paths are relative to the form's template file (tmpl-1.txt).
     
  3. Create the "guestbook.txt" template file
    *noHTML*
    <HR>
    On [*date-time*], [required-name] <A HREF="mailto:[email]></A> from [$REMOTE_ADDR]  wrote:
    
    [required-comments]

Notice that we are placing form variables (denoted by the variable name surrounded by brackets) and system variables, as well as HTML codes, since this template will be used to write to an HTML file (my-book.html).

The trick to get this to work as a Guestbook is to first create the my-book.html file with either notepad, or any HTML editor you want to. When the form is processed, MailPost is going to append the information that it formats using the guestbook.txt file to the end of the my-book.file. Because of this, you have to remove the </BODY> and </HTML> tags at the end of the my-book.html file after you first create it. This lets MailPost append the new guestbook info to the HTML file. Although it's not correct HTML code (since there are no closing </BODY> or </HTML> tags) it should not cause a problem for most browsers. If you ever edit your guestbook HTML file with an HTML editor, make sure that you remove the </BODY> and </HTML> tags it may add to the end when you save it.

Also notice the special MailPost tag *noHTML* , which is the first line of the SaveUsing template file. This tag has to be on the very first line of the SaveUsing template file, and it must be the only thing on that line.

When MailPost encounters the *noHTML* tag in the SaveUsing template file, MailPost will convert all HTML code received in a form variable to printable characters.
Security alert!! Guestbooks can be security problems if people are allowed to include HTML statements in their messages. In order to provide better security, it is suggested that you insert the *noHTML* tag in any SaveUsing template file that will be displayed in an HTML document.

  
Name
Email

Comments

Your IP address will be included in our guestbook

  
 

MailPost Homepage