Skip to the Main Content

Note:These pages make extensive use of the latest XHTML and CSS Standards. They ought to look great in any standards-compliant modern browser. Unfortunately, they will probably look horrible in older browsers, like Netscape 4.x and IE 4.x. Moreover, many posts use MathML, which is, currently only supported in Mozilla. My best suggestion (and you will thank me when surfing an ever-increasing number of sites on the web which have been crafted to use the new standards) is to upgrade to the latest version of your browser. If that's not possible, consider moving to the Standards-compliant and open-source Mozilla browser.

May 3, 2003

Validating Comments

Update:

The plugin has a new home page. Look there for the most up-to-date installation instructions.

I actually got a couple of emails about my previous post on implementing Comment Validation in a MovableType blog. Evidently, there’s some interest out there. So here is the first in an occasional series of “How-To” articles on MovableType.

Alexei Kosut wrapped the W3C Validator in an MT plugin. I extended his plugin by adding some more MT Template tags, correcting some errors where the Validator was sending invalid output and customized the Validator’s output templates to make them more suitable for inclusion in a weblog comment preview window. More recently (5/26/2004), I updated the plugin to incorporate the newer, more user-friendly error-reporting in the new W3C Validator and added (6/22/2004) some portability fixes. Since Alexei seems to have lost interest, and since my changes are now quite substantial, you can now get my revised plugin with all the changes rolled in.

The plugin has a bunch of prerequisites. You may need to install or update several Perl modules:

  • Config::General (version 2.06 or later)
  • File::Spec (version 0.8 or later)
  • HTML::Entities
  • HTML::Parser (version 3.25 or later)
  • HTML::Template (version 2.6 or later)
  • IO::File
  • IPC::Open3
  • Set::IntSpan
  • Text::Iconv
  • Text::Wrap

If you’re not already using the CPAN module, then perhaps now would be a good time. With CPAN, you can install the whole lot with a single command,

install  HTML::Template Bundle::W3C::Validator

or, if you have most of what you need already, you can install just the missing modules with an appropriate “install ...” command.

“But wait!” I hear you cry, “I don’t have root on my webhost. How can I use CPAN?” Well, the folks who designed it were helpful enough to design it so that you can also install files locally (in your MT/extlib directory):

perl -MCPAN -e shell
o conf makepl_arg "LIB=/your/path/to/MT/extlib \
INSTALLMAN1DIR=/dev/null \
INSTALLMAN3DIR=/dev/null"
install HTML::Template Bundle::W3C::Validator

CPAN puts the modules through a rigorous set of self-test before installing them. Even if a module passes every single self-test but one, CPAN will err on the side of caution and not install it. For your purposes, this is way more conservative than you need. If a module fails a couple of tests, but passes almost all of the rest, just do a

force install ModuleName

That is pretty sure to be safe.

You may also need a copy of the onsgmls program from the OpenSP Project. It comes pre-installed with most flavours of Linux. For MacOSX, I got mine from Fink (“fink install opensp3”). If worst comes to worst, you can download and compile the OpenSP source. In any case, you may have to edit /plugins/validator/config/validator.conf to point to the location of the onsgmls executable. In my case, it reads

SGML_Parser  = /sw/bin/onsgmls

Now that you have the SGML parser installed, you need a set of DTDs for it to work with. Download and unpack sgml-lib and install it as plugins/validator/sgml-lib .

One more gotcha has to do with whether, in Perl, $0 returns just the filename or the full path on your operating system. If the Validator complains about being unable to find its configuration files, set the path to your plugins directory

PluginPath  /full/path/to/plugins

in mt.cfg and the error will go away.

The output of the Validator is controlled by a bunch of template files in plugins/validator/templates/. The relevant ones are probably results.html (the main template controlling the output), valid.html (included if the page validated) and invalid.html (included if there were errors). You’ll want to tweak them so that the output looks like what you want. And you’re free to use CSS to style them as you wish.

But first, we need to modify our MovableType templates. The key one will be the Comment Preview Template. Let me step you through mine.

<$MTInclude module="DTD"$>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><$MTBlogName$>: Comment Preview</title>
<$MTInclude module="HeaderLinks"$>
</head>
<body>
<$MTInclude module="SmallBanner"$>
<div class="blog">
<h2 class="comments-head">Preview Your Comment</h2>

As you can see, a lot of stuff in my templates is abstracted into modules. I can change the DTD of all the pages of my blog by editing one template module. That module currently reads:

<?xml version='1.0' encoding='iso-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" >

Being able to change something by editing one template module and having the change reflected blog-wide is a very good thing.

<MTValidate>
<$MTInclude module="DTD"$>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Your Comment</title>
</head>
<body>
<h3 class="title"><$MTCommentPreviewSubject strip_controlchars="2" remove_html="1"$></h3>
<$MTCommentPreviewBody safe_urls="1" smarty_pants="2"$>
<p class="comments-post">Submitted by <$MTCommentPreviewAuthorLink spam_protect="1"$> at <$MTCommentPreviewDate$></p>
</body>
</html>
</MTValidate>
<form method="post" action="<$MTCGIPath$><$MTCommentScript$>">

The contents of the <MTValidate>...</MTValidate> gets passed to the Validator. Note that the Validator expects a fully-formed (X)HTML document, right down to the DTD. Also, I happen to be using the SmartyPants and safe_href plugins.

If the comment had errors, we’ll get a sad message listing the errors. If it was valid XHTML, we’ll get a happy message and then we’ll want to present the user with a preview of his comment and an opportunity to post it. The contents of <MTValidateIfValid>...</MTValidateIfValid> only appear if the Validator found no errors.

<MTValidateIfValid>
<div class="blogbody">
<$MTCommentPreviewBody safe_urls="1" smarty_pants="2"$>
<span class="comments-post">Submitted by
<$MTCommentPreviewAuthorLink spam_protect="1"$> at
<$MTCommentPreviewDate$></span>
</div>
<fieldset class="blogbody">
  <input type="submit" name="post" value="&nbsp;POST&nbsp;" />
</fieldset>
</MTValidateIfValid>

We only want to display the comment preview if the comment was valid XHTML, and the same goes for the “POST” button.

Next, we present the user with the opportunity to edit the comment and preview it again. Note that there are some additional form fields, because we’re using Alexei’s most excellent MTThreadedComments plugin.

<h2 class="comments-head">Edit Your Comment</h2>
<fieldset class="blogbody">
  <input type="hidden" name="entry_id" value="<$MTEntryID$>" />
  <input type="hidden" name="static" value="<$MTCommentPreviewIsStatic$>" />
  <label for="author">Name:</label><br />
  <input id="author" name="author" value="<$MTCommentPreviewAuthor encode_html="1"$>" /><br />
  <label for="email">Email Address:</label><br />
  <input id="email" name="email"  size="30" value="<$MTCommentPreviewEmail encode_html="1"$>" /><br />
  <label for="url">URL:</label><br />
  <input id="url" name="url" size="50" value="<$MTCommentPreviewURL encode_html="1"$>" /><br />
<input type="hidden" name="parent_id" value="<$MTCommentPreviewParentID$>" />
<label for="subject">Subject: </label><br />
<input id="subject" name="subject" size="30"
       value="<$MTCommentPreviewSubject encode_html="1"$>" /><br />
  <label for="text">Comments:</label><br />
  <textarea id="text" name="text" rows="10" cols="48"><$MTCommentPreviewBody convert_breaks="0" encode_html="1"$> </textarea><br />
  <input type="submit" name="preview" value="&nbsp;PREVIEW&nbsp;" />
</fieldset>
</form>

Note, again, that there’s only a “PREVIEW” button here. We want the commenter to preview the comment again, if it’s been edited.

Finally, if there are any, we’ll present the user with a listing of previous comments and trackbacks (using the MTSimpleComments plugin) on this post. The same template module used to provide this listing is used to list the comments and trackbacks on the individual archive page. To get the conditional display, we use the Compare plugin.

<MTIfGreater a="[MTSimpleCommentCount]" b="0">
<h2 class="comments-head">Previous Comments &amp; Trackbacks</h2>
<MTInclude module="FollowupList>
</MTIfGreater>
</div>
</body>
</html>

Now all we need to do is remove the “POST” button from the Comment Listing Template and the Comment Error Template, so that people need to preview their comment (and, in so doing, run it through the Validator) before they can post it.

Try it out! Type a comment and preview it. Try seeing what happens if you stick in some invalid HTML. Nifty, huh?

Update (11/27/2006): More Checks

Version 0.4 of the plugin incorporates a new configuration option in /plugins/validator/config/validator.conf . The onsgmls parser doesn’t really check XHTML documents for well-formedness. To get an extra layer of protection, you can set

XHTML_Check  = 1

which runs the comment through a real XML parser, ensuring that it is well-formed. To use this option, you’ll need the XML::LibXML Perl Module.

The new version also incorporates yet more user-friendly error messages from version 0.74 of the W3C Validator.

Posted by distler at May 3, 2003 11:31 PM

TrackBack URL for this Entry:   http://golem.ph.utexas.edu/cgi-bin/MT-3.0/dxy-tb.fcgi/155

17 Comments & 15 Trackbacks

Re: Validating Comments

Hmmm… Don’t mind me, I find this interesting and I’d like to try it out… so below will be some badly formated HTML…

bad formating with bold and italic…

  1. bad list item 1
  2. bad list item 2

Thanks for the test :)
———————–>
OH WOW! It works even better than I dreamed… maybe when I have a few hours I’ll implement this :)

Posted by: Jai on May 7, 2003 3:39 PM | Permalink | Reply to this
Read the post In brief: bread machine edition
Weblog: dive into mark
Excerpt: I didn't know yeast ever expired. I thought it was like Twinkies, and fruitcake.
Tracked: May 15, 2003 5:06 PM
Read the post Validate MT Comments
Weblog: ecrosstexas: the texas blog
Excerpt: Jacques Distler, Physics Professor at UT Austin provides the first two parts in a series of "How-to" articles on Validating Comments and Bullet-Proofing II in Moveable Type....
Tracked: May 19, 2003 2:41 PM
Read the post Validating Comments in MT
Weblog: Webspiffy: Elsewhere
Excerpt: An awesome modification I'm going to install when I have some free time.
Tracked: September 4, 2003 10:55 PM

Re: Validating Comments

I hope you still read this comment since this post is several months old. Anyway, I’d really like to install Comment Validation on my weblog, but I can’t seem to get all the Perl modules.

I installed CPAN and tried install Config::General and install Text::Iconv, but the result was “Searching for ‘Module::Name’ returned no results. Try a broader search first”. Is there a particular place where I download these modules?

Without these modules I can’t even try installing the Comment Validation, so I’d appreciate any help you could give me.

Posted by: Bas Hamar de la Brethonière on September 23, 2003 10:02 AM | Permalink | Reply to this

Re: Validating Comments

Never mind, I already found the required modules using the Online CPAN Search. Sorry for the useless post.

Posted by: Bas Hamar de la Brethonière on September 23, 2003 10:12 AM | Permalink | Reply to this

Re: Validating Comments

This is not so much a response to this post about validating comments (which by the way is clear cut and concise), but a plea for a similar guided tour through the MTThreadedComments that you mention. I really want that plugin, but somehow it doesn’t work for me…
I’ve cast lines out in the MT Support forum, but no-one has bitten yet.

Posted by: Paul on December 1, 2003 3:12 PM | Permalink | Reply to this
Read the post Time to convert to XHTML 1.1
Weblog: Eclectic Echoes
Excerpt: After the New York trip, I think it will be time to change the site over from XHTML(eXtensible Hypertext Markup Language) 1.0 Transitional to XHTML 1.1. The changes should be limited, mostly changing the javascript and form areas. The main area's right...
Tracked: January 13, 2004 3:46 PM

Re: Validating Comments

I’m going to try one of my favorite messups here.
my link without an ending quote in the ‘a href’ part.

Fascinating. It told me it was valid, but changed my link to <a>my link</a>, leaving out the ‘href’ and actual link.

Posted by: Kathy K on February 7, 2004 6:18 PM | Permalink | Reply to this

Re: Validating Comments

This is just a test

Posted by: jt on February 9, 2004 10:30 PM | Permalink | Reply to this
Read the post Sustaining Validation
Weblog: asterisk*
Excerpt: I don't want to open a can of worms here, but I thought it might be helpful to share my experience over the last week trying to put in place a better system to keep Asterisk valid. Don't worry I wont bore you with all the details. As you may...
Tracked: June 19, 2004 9:49 AM

Re: Validating Comments

Nice updates!
now i think plugin installed

Posted by: Dan on June 22, 2004 5:38 PM | Permalink | Reply to this

Re: Validating Comments

How do you do it with WordPress? are there any such plugins available to validate comments for WordPress?

Posted by: Jax on July 29, 2004 1:26 AM | Permalink | Reply to this

WordPress plugin

To my knowledge, there is currently no WordPress plugin, with comparable functionality, available.

Posted by: Jacques Distler on July 29, 2004 8:51 AM | Permalink | PGP Sig | Reply to this

Re: Validating Comments

What if my name contains an ampersand? Is there anything that we can do to protect our comments from ampersands?

I’m asking because it happened for the first time to me the other day. And once is enough for me to be concerned.

Posted by: Me, Myself & I (Joshua Kaufman) on August 1, 2004 1:41 PM | Permalink | Reply to this

Re: Validating Comments

In short, we don’t f*#$ around checking only some of the form fields; we check all of them.

See my (revised) post on the subject.

Posted by: Jacques Distler on August 2, 2004 12:11 AM | Permalink | Reply to this
Read the post validating MT
Weblog: monologue
Excerpt: W3C Validator plugin for MovableType. One of the more useful plugins in my honest opinion....
Tracked: August 28, 2004 9:51 AM
Read the post Why 'More Than Valid'?
Weblog: More Than Valid
Excerpt: Small Thanks Thank you to Eric Meyer for linking me in his Distractions list, and to those of you who found this article via that link. The site is not live yet, and this is just a sample article so...
Tracked: December 4, 2004 8:55 PM
Read the post Validation!
Weblog: Upon Reflection
Excerpt: This weblog is now Valid XHTML 1.1 plus MathML 2.0! It turned out to go more smoothly than I thought. There were only a few troublesome entries that I really had to struggle with. Most of my entries validated once...
Tracked: December 22, 2004 1:33 AM
Read the post Fear Me, for I Am Root
Weblog: Upon Reflection
Excerpt: Setting up a webserver, posting course material online, and creating a weblog requires a deep exploration of computer geekness. The downside is I am a very reluctant geek. I don't experience a sudden thrill while validating HTML code. I don't...
Tracked: January 7, 2005 11:31 AM
Read the post New Look, XHTML 1.1 and MathML
Weblog: Procrastination
Excerpt: You might have noticed the new look of this weblog. It all started due to Asif and Jacques Distler. Asif just started using LaTeX formulae on his weblog and Jacques has been doing so for quite a while. Asif is...
Tracked: January 9, 2005 11:03 PM

Re: Validating Comments

If worst comes to worst, you can download and compile the OpenSP source. In any case, you may have to edit /plugins/validator/config/validator.conf to point to the location of the onsgmls executable.

One thing you missed there is that the SGML Library Path also needs to be set to the correct location. In fact, that needs to be done whether OpenSP is pre-installed or compiled by you since the default path “validator/sgml-lib” doesn’t exist.

Posted by: Zack on January 19, 2005 2:16 AM | Permalink | PGP Sig | Reply to this

sgml-lib

Ack!

What’s missing is the instruction to install a copy of sgml-lib
in the plugins/validator directory.

Alexei had that instruction in his writeup. I neglected to include it in mime.

Fixed.

Posted by: Jacques Distler on January 19, 2005 9:40 AM | Permalink | PGP Sig | Reply to this

Re: sgml-lib

Thanks. Somehow I missed it in Alexei’s instructions, probably because I was more focussed on yours.

Also, I had to put in the absolute path for sgml-lib in validator.conf instead of a relative path.

Posted by: Zack on January 19, 2005 1:04 PM | Permalink | PGP Sig | Reply to this
Read the post Front-end and Back-end Changes
Weblog: Procrastination
Excerpt: There have been a lot of changes here recently, most of them on the back-end. Most of this work was related to having a bilingual (English and Urdu) blog along with MathML equations. This required valid XHTML 1.1 and serving...
Tracked: February 11, 2005 8:25 AM
Read the post Drupal and XML
Weblog: brianpuccio.net
Excerpt: Everyone has heard of the latest standard, XHTML. Pretty much every blogger proudly displays his or her tag of validation, maybe even a valid CSS tag as well. That's good and fine, but are you serving the document as an XML document or just as tag soup?
Tracked: July 2, 2005 9:57 AM
Read the post Are You Being Served? -- Part II
Weblog: Upon Reflection
Excerpt: Step 3: MathML At this point you should have valid XHTML 1.1 pages served with the correct MIME type to all the good little browsers.... It is much easier to use some kind of shorthand to enter equations, and let Movable Type convert it to MathML when...
Tracked: September 30, 2005 1:01 PM

Re: Validating Comments

What is a validator ?

Posted by: Bob on February 28, 2006 8:47 AM | Permalink | Reply to this
Read the post Bulletholes
Weblog: Musings
Excerpt: Henri Sivonen bursts my bubble.
Tracked: November 25, 2006 2:38 AM
Read the post New Look, XHTML 1.1 and MathML
Weblog: Procrastination
Excerpt: You might have noticed the new look of this weblog. It all started due to Asif and Jacques Distler. Asif just started using LaTeX formulae on his weblog and Jacques has been doing so for quite a while. Asif is...
Tracked: March 14, 2007 7:39 AM

Re: Validating Comments

I can neither confirm or deny the sexuality of my cat.

Posted by: martha on November 27, 2007 8:35 PM | Permalink | Reply to this

Re: Validating Comments

Private Fund Management - how to invest
is an international investment company specializing in asset management services. During its long history, it has achieved and occupied a stable position in the financial market and won the confidence of numerous investors from all over the world.
Asset management
Asset management comprises the management of the client’s funds conducted on the basis of the contract signed by the investor and the management company. An investor transfers his or her powers to the management company, which chooses a professional and effective investment strategy based on the client’s aims and financial capability.
The traders react to any fluctuations on the financial market by immediately correcting the investment strategy in order to achieve and maintain high profit levels for an investor.
Asset management for our clients
• The reliability of cooperation with a professional investment company.
• No restrictions concerning the sum of the initial investment.
• Guaranteed profit rate acquired at specified periods of time.
• All decisions concerning the management of the acquired profits are made by the investor himself.
• The management company works hard to increase the investor’s income since the size of the brokerage received by it depends on the profit acquired by the client.
Does this investment method suit you?
Business development
The main reason for investing money into something is the formation of an additional source of passive income. If a client chooses the right way of investing money, he or she will be able to enjoy a certain degree of freedom in the development of his or her main business. Having a predetermined regular income, you will be able to expand the influence of your company at the market, invest the acquired profits into the development of new solutions and products, and define the prospective growth taking into consideration the peculiar features of your own stabilization fund.
Personal aims
By transferring a part of your funds to an asset management company, you will be able to figure out how you are going to use the acquired additional income for your own purposes. This sum used to be just a kind of stabilizer, but now you will be able to spend more money on recreation and unplanned purchases without increasing the size of the supply subtracted from your regular income.
Increasing the assets
By increasing the amount of funds transferred to an asset management company by means of acquired profits you will be increasing your own capital. At the same time the money doesn’t just get accumulated – it keeps on working for you. Consequently, the larger is the invested sum, the more profit you get from it.
The advantages of transferring free funds into asset management
 The ability to build up your own investment business.
 Freedom in the process of designing more ambitious development strategies.
 Guaranteed stability and substantial amount of profits.
 Additional funds that can be used in the realization of one’s personal aims.
 Capital growth and steady increase of the active income.
The advantages that we offer
Individual approach and absolutely straight dealing with our clients. We strive towards close long-term business relationships that are able to bring mutual profits to our clients, partners, and ourselves. Guided by the willingness to achieve our common goals, we pay maximum attention to each of our investors. We value long-term relationships with our investors much higher than one-time transactions – that’s why we keep on doing our best to give maximum confidence to our clients and ensure the perfect performance of our liabilities.
Reliability. We minimize the risks taken by our clients by means of investment diversification and the utilizations of a specific investment strategy. All the investments that we manage get insured at the conditions that guarantee fullest protection of our clients’ interests.
Blameless reputation. During our history we have signed a lot of profitable contracts. Long years of successful operation at the international market have resulted in the establishment of our company’s blameless reputation based on the professional operation of our staff as well as the highest quality of the provided services.
Safe Investment Management Conception. Our work is based upon the principles; the effectiveness of which has been tested and proven in practice.
• Objective valuation of expectations.
• Detailed reports about the achieved results.
• Scrupulous risk management.
• Full correspondence of our activity to the current legislation.
• The willingness to find an appropriate solution for every particular problem.
• Creative approach towards the problems experienced by our clients.
• Aiming at the establishment of long-term business relationships with our clients.
The clients working with Private Fund Management should be fully confident of the reliability and the potential profitability of their investment. Our employees will help you choose the most convenient and well-paying investment option for you after picking up the appropriate investment strategy and investment portfolio.
Investment portfolios
While choosing the appropriate investment means one will always have to look for the happy medium between two indices: profitability and possible risks. These indices are in direct relation to each other - the bigger is the potential profit, the bigger is the potential risk. It has to be noted that the concept of risk is getting less and less relevant these days since within the past seven years of our operation at the financial market none of our clients have ever received profits lower than those agreed upon during the process of signing the contract. We offer solutions able to help each of our customers to choose the investment means that is the most profitable for him or her in particular.
What is an investment portfolio?
An investment portfolio is the combination of assets that you invest your money into. The process of building up an investment portfolio is based upon the process of choosing securities. The main reason for creating a portfolio is pretty simple – if done correctly, it will allow you to supply your set of securities with such investment features (profitability and risk) that cannot be achieved by purchasing only stocks or bonds, for instance. Combination is the only key to creating a good investment portfolio.
Peculiar features of different investment portfolios
All investment portfolios are built up in accordance with one of the following strategies:
• The strategy aimed at the aggressive capital growth stimulation with high level of risk. Potential annual profitability of this strategy can be estimated at about 35%. This strategy is based upon the utilization of tools with a high level of risk: shares, futures, and options.
• The strategy aimed at low-risk investment and intended for steady capital growth (about 22% annually). Stocks can serve as an example of low-risk investment tools.

By combining high- and low-risk approaches in different proportions, the experts of Private Fund Management develop investment portfolios based on the requirements set by different clients.

Posted by: GregorioGower on April 17, 2008 8:36 AM | Permalink | Reply to this

Post a New Comment