The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Displaying Comments | Up | Handling Submission Errors »

Chapter 7: Comments

Creating a Comment Submission Form

Problem

You want to create a form that accepts comment submissions.

Solution

Create an HTML form that submits its input to the Movable Type comment script or instead use the MTCommentFields tag.

Discussion

"Displaying Comments" discusses how to lay out comments. If there isn't a way for readers to make comments, then there won't be any to display. Here is a simple, example form layout that could be used in an individual entry archive template.

 <form method="post" action="<$MTCGIPath$><$MTCommentScript$>">
 <input type="hidden" name="static" value="1" />
 <input type="hidden" name="entry_id" value="<$MTEntryID$>" />
 
 <p><label for="author">Name:</label><br />
 <input id="author" name="author" /></p>
 <p><label for="email">Email Address:</label><br />
 <input id="email" name="email" /></p>
 <p><label for="url">URL:</label><br />
 <input type="text" name="url" id="url" /></p>
 
 <p><label for="text">Comments:</label><br />
 <textarea id="text" name="text" rows="10" cols="50"></textarea>
 </p>
 
 <div align="center">
 <input type="submit" name="post" value="Post" />
 </div>
 
 </form>

The form is set up with MTCGIPath and MTCommentScript; these create the URL where the input is submitted. Next are two hidden fields that the mt-comments.cgi script requires for processing. The static field tells the comments script how to generate the comment link, which is not stored. The entry field is the ID that the comment is associated with.

Next we move on to the labels and inputs used to collect the commenter's name, email address, and URL. (This example covers commenting that does not require registration. A TypeKey compatible registration system will provide the name and email address for us.) Using a radio button, this example form allows the commenter to decide whether they'd like the system to remember their information for future comments. A text field is provided for the actual comment, and a Post button for submitting the input to the associated comment script.

A simple way of implementing such a form is to use the MTCommentFields tag, which handles all of this for you by inserting a generic comment submission form into your template. By using this tag, you have the advantage not needing to create the comment form yourself, but you sacrifice a certain amount of flexibility in how the form is constructed.

Enabling Comment Preview

MT's built-in commenting system can be enabled to allow commenters to preview what they've written before they submit it. This feature is enabled by the system Comment Preview template, which requires some added considerations to the standard comment form layout.

Your layout of the comment being previewed uses different, though similarly named tags.

  • MTCommentPreviewAuthor
  • MTCommentPreviewIP
  • MTCommentPreviewAuthorLink
  • MTCommentPreviewEmail
  • MTCommentPreviewURL
  • MTCommentPreviewBody
  • MTCommentPreviewDate

These tags all have the same meaning as the like-named comment tags (sans the Preview) discussed earlier. The only real difference is that these tags represent content that has not been stored in the system yet.

These tags should also be used to set the values of the form elements the commenter can use to make changes to their text. Don't forget to use the encode_html filter on all of them.

A comment preview template also has one additional tag at its disposal: MTCommentPreviewIsStatic. This tag is used inside of the form to indicate to the system where to redirect users after posting a comment. Since the preview function and template are shared by both comment interfaces, the value of the static will vary depending upon use. Here is how we use it in our preview form:

 <input type="hidden" name="static" value="<$MTCommentPreviewIsStatic$>">

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.