A replacement for <MTCommentFields>

| 28 Comments | 21 TrackBacks

Because of the complicated logic necessary to integrate TypeKey authentication into MT3D's template code for comments, a new template tag was created to automatically generate all of the necessary code - <MTCommentFields>. This new tag can be seen on the default Comment Listing, Comment Preview, and Comment Error templates for MT3D. Interestingly, this new tag was not used on the default Individual Entry Archive template.

Unfortunately, this tag has a few problems:

  • Comment entry fields (Name, E-mail, URL, Comment text) are not remembered when a comment is previewed or a comment error occurs.
  • Some of the code produced is not valid XHTML.
  • The code produced cannot be edited, unless you're up to hacking /lib/MT/Template/Context.pm.
  • There's actually two comment forms within the code; one is chosen for display depending on whether TypeKey registration is required. The forms are not identical, even taking into account the differences that should be there.

I liked the idea of the <MTCommentFields> tag, but not the fact that it was somewhat broken and extremely difficult to fix. So I came up with the following workaround until (hopefully) the next release of MT3 fixes these problems.

The first thing you need to do is to create a new template module in your weblog. Name the module "CommentFields". Click on or download the CommentFields.txt link, paste the code from that file into the Module Body, and save the module.

Next, you need to replace the <MTCommentFields> template tag with an <MTSetVar> and <MTInclude> tag to use the module code instead of the built-in MT code.

On the Comment Listing, Comment Preview, and Comment Error templates, locate the <MTCommentFields> tag and replace it with the code shown below.

The code below can also be used on the Individual Entry Archive template, but on that template, all of the code between and including the <MTIfRegistrationRequired> and </MTIfRegistrationRequired> tags (over 100 lines of code) needs to be deleted and replaced with the code below. Additionally the template code between and including the <script> and </script> tags immediately following the </MTIfCommentsAllowed> tag needs to be deleted as well.

The new code to replace the <MTCommentFields> tag:

<$MTSetVar name="preview" value="0"$>
<$MTInclude module="CommentFields"$>
  • On the Comment Listing and Individual Entry Archive templates, set the 'value' attribute in the <$MTSetVar$> tag to "0".
  • On the Comment Preview and Comment Error templates, set the 'value' attribute in the <$MTSetVar$> tag to "1".

New addition for popup comments: The Comment Listing template requires one more MTSetVar tag to properly set the "static" parameter in its comment form and TypeKey links. Use the code below only in the Comment Listing template:

<$MTSetVar name="static" value="0"$>
<$MTSetVar name="preview" value="0"$>
<$MTInclude module="CommentFields"$>

Save the templates, and rebuild the Individual Entry Archives if that template was modified to use the CommentFields template module.

The code I supplied in the CommentFields.txt file fixes the Comment Preview problem, the obvious invalid XHTML I spotted, plus makes both comment forms in the code as nearly equal as I could make them. The code can now be edited (if you desire) by editing the CommentFields module instead of hacking lib/MT/Template/Context.pm.

I haven't thoroughly tested the code in all scenarios. It seems to work using MT3D's default of inline, non-dynamic comments (which is how I am using it now). This is something else that hopefully will be fixed in the next version of MT3, but the Comment Preview not remembering the fields really bugged me and I didn't want to wait for the next release of MT3.

I have mixed feelings on sharing it - it is a lot of code that may or may not work for everyone and there's a lot that can go wrong as someone tries to implement it. If you can use it and make it work, great! If not, I'll try to help the best I can but there's no guarantees.

Update 02-Jun-2004: I discovered something odd in the comment forms while I was writing a comment this morning. I wrote one HTML and one MT tag in the comment text, both surrounded by escaped angle brackets (&lt; and &gt;). When I previewed the comment, MT decoded the angle brackets so they were no longer escaped (< and >). If I previewed the comment a second time, MT's sanitize function removed the tags from the comment.

MT seemed to be performing a 'decode_html' on the MTCommentPreviewBody text. I added an encode_html="1" attribute to the MTCommentPreviewBody tag in each of the CommentFields module's forms to re-encode it back. With the encode_html attribute, MT no longer decodes HTML entities that are in the comment text when it is previewed.

Update 23-Jun-2004: CommentFields module code updated to (hopefully) work with popup comments:

  • Requires addition of <$MTSetVar name="static" value="0"$> tag to Comment Listing template. If tag is omitted (such as on Individual Entry Archive template), module code will use a default "static" value of "1".
  • Module code now looks at <$MTCommentPreviewIsStatic$> tag on Comment Preview and Comment Error templates (where preview="1") to determine proper "static" value (so above MTSetVar tag is not required on Comment Preview and Comment Error templates).
  • Links to sign in and out of TypeKey updated to properly reflect static value and return user to appropriate page after signing in and out.

Update 24-Jun-2004: Changed javascript code that retrieves TypeKey commenter name to get it from cookie on user's machine instead of from mt-comments.cgi on server. This eliminates refresh problem when signing in and out of TypeKey that occurs on some browsers (notably, Internet Explorer for Windows). Thanks to Hirotaka Ogawa for the code.

21 TrackBacks

Friends and Comrades from Bow. James Bow. on June 1, 2004 1:57 PM

My friend, Greg, is counting his blessings today. His town was among many in the Midwest that were hit by a substantial outbreak of tornadoes. I heard that as many as ninety tornadoes may have been involved in this outbreak.... Read More

Refueled from writing my name in water on June 3, 2004 2:08 PM

I had a long, lovely weekend with my girl. As she said, it was restorative -- sometimes, the old LDR makes cartoon automobile cough-cough-running-out-of-gas sounds. We gave it some Popeye spinach and it got all bouncy again. Rorcha had his... Read More

MT3D Bugs from xGrape.net on June 7, 2004 2:13 AM

I posted to the MT forums about a couple problems I had after updating the templates yesterday. I'm currently investigating the solutions, and have applied the one concerning "remember me"-cookies, with no luck. Maybe I have to clear my cookies... Read More

I just upgraded this site to MovableType 3.0D. Didn't have a reason to do it, didn't have a reason not to. Nice shiny new & paid-for license. The new interface is good and rebuilding is faster. Seems to have gone... Read More

Comment Registration from Dewberry {Clack} on July 1, 2004 1:46 PM

If you would like to leave comments at Dewberry, you will need to sign up for a TypeKey account. This will help prevent comment spamming and make us all happier! It also means that you'll only need to register once to comment at countless MT driven sit... Read More

one more chance from I Want To Hug Kafka on July 2, 2004 11:47 AM

Okay, Movable Type 3.0, I'll add this comments tweak and hope for the best! In the meantime, guys, don't try to comment on anything, it will end up being weird.... Read More

Folks, I've decided to stick with Movable Type 3.0D, even though the commenting system is fairly whack. Unfortunately, MT-Blacklist is incompatible with the newest version of Movable Type, but there ought not to be much comment spam with the new proces... Read More

Design: Inspired by or ripped-off from? from Katieweb: a user-centered viewpoint on August 12, 2004 8:42 PM

The layout and usability of Andy Baio's blog, Waxy.org, is exceptional. Many blogs are difficult to read and are full of text without clear navigation. Bloggers are subject to the default template setup, and customization can be tricky. (Particularly f... Read More

Either 6 Apart, owners of Movable Type, are assholes, or they are stupid. I hate to think of them as either, but I am forced to tonight. you see, the problem comes from an attempt to move Kyrah, AKA Codemuffin's... Read More

I've done some sprucing up. With some help from Jamison, I've upgraded from 3.01d to 3.11. (That explains the blog's new warm sparkly glow you may have noticed.) I installed MT Blacklist 2.01b, and that seems to be working well.... Read More

Unable to sleep through the din of fans and dehumidifiers last night, I figured I’d do something productive and finally get around to doing all the templates to this site that have been neglected. Last night I setup templates for: comment pendin... Read More

New Feature Added from One Moment At A Time on November 4, 2004 8:27 PM

I've added a new feature where you can now be notified of new comments to posts you've previously commented on. It uses the MT-Notifier plugin, and thanks also goes to The Tweezer's Edge for this article on replacing the MTCommentFields... Read More

I promised myself to stay focused in this weblog, but a few Movable Type users might find this useful. In the course of modifying templates in MT3 that to tickle... Read More

Das eigentlich recht gute template-System von Movabletype stößt unverständlicherweise bei der Vorschau und der Fehlermeldung von Kommentaren an seine Grenzen. Es gibt zwar einen PHP-workaround auf mezzoblue, der auch gut zu funktionieren scheint, do... Read More

Das eigentlich recht gute template-System von Movabletype stößt leider bei den Vorschau- und der Fehlermeldungsseiten des Commentsystems an seine Grenzen. Es gibt zwar einen PHP-workaround, der auch gut zu funktionieren scheint, doch nur um die Typek... Read More

Upgrade from Much Madness is Divinest Sense on January 8, 2005 8:50 PM

Okay, upgrade to Movable Type 3.14 seems to be successful. So far, I like the new features. An upgrade was necessary because I just couldn't take advantage of the new plug-ins with 2.66. Also, 3.14 has more safeguards against comment... Read More

Look Into This from Daniel J. Luke's Weblog on January 17, 2005 8:26 AM

Because of my hackery to allow threaded comments, my comment-submit form doesn't look like it lets you use a TypeKey... Read More

Fixed it... from The Unknown Geek on March 14, 2005 11:42 AM

Thanks to the help of TweezerMan over at The Tweezer's Edge (here and here), I've got the "Remember Me" function on the comments working again... =)... Read More

Comment Previews from Sean Slavin Photography on March 26, 2005 7:39 AM

I’ve been trying for the past couple of days to get an effective comment preview running. This morning I thought I made a breakthrough but got stymied by the tag. A bit of Googling turned up this article which turned... Read More

Moo! Organization from Moo! The Musings of a Plaid Cow on May 9, 2005 3:20 AM

Another re-org. Perhaps this one will go better that the last one. As with the last time, the categories have again been shifted about. Perhaps this time I really know what I want to be writing about. Software has been... Read More

Behind the Scenes: Hacking MT Comment Previews from www.matthew-anderson.net | matt he wanders on on January 9, 2006 1:14 PM

While my blogging lately has been sporadic at best, I have been doing some other things around here. Over the last few months, especially after starting up Stopping Points, I received a lot of suggestions and I have taken them... Read More


Thanks for these changes. They fix the obvious XHTML error, but I've encountered a new problem.

When I try to sign into Typekey from my blog, I encounter the following error:

"The site you're trying to comment on has not signed up for this feature. Please inform the site owner".

Now, I _know_ that I have my webblog set up for TypeKey. I even have the twenty-digit code and everything. Do you have any idea what's up?

That error is a TypeKey error - it thinks that your site is not in the list of sites registered in your TypeKey profile. What did you enter as the URL for your site (below the TypeKey token on your profile page at www.typekey.com)?

Thanks for your reply.

I entered http://www.bowjamesbow.net/ in my profile. That should work, right?

As I said in my nonTypekey comment, the URL I used was http://www.bowjamesbow.net/ -- I would have thought that worked.

Oddly, though: if I sign in on TypeKey on your blog, and then go back to my blog, the feature works. Weird.

Yeah, I found that out when I was trying to figure out what you were seeing. I had signed into TypeKey through my weblog, went to your weblog and had no problem, so I (almost) thought you fixed your problem.

One question - do you have any plugins installed, particularly MT-Blacklist?

The only thing I know to do is try different variations of your URL as suggested in this MT forum thread and see if any of them work, such as:

- http://bowjamesbow.net/
- http://www.bowjamesbow.net/cgi-bin/
- http://www.bowjamesbow.net/cgi-bin/mt-comments.cgi

I noticed your comments page does not have the javascript code it needs at the top of the page. I doubt that it has anything to do with your TypeKey problem, but you might check out my post about that issue anyway.

Thanks aplenty. http://www.bowjamesbow.net/cgi-bin/ worked!

Plugins? Why yes, I do. I run:

MTMacros (for smilies and stuff)
MTCloseComments (as effective as MTBlacklist in stopping comment spam)

I, of course, removed MTBlacklist because it's incompatable with MT 3.0

Thanks! Somebody mentioned to me the other day that "Remember Me" did not seem to be working on my weblog. I have implemented your changes and hopefully now that is fixed. (I'm sure it is!)

Thank you so much for this fix/workaround/brilliance. I'm using your code on my blog now. I have noticed another problem, though, but it is not in your CommentFields module.

When the commenter is signed into TypeKey, and previews his comment, there is no name displayed in the "Posted by" line. For example, I am previewing my comment right now and below the preview area, above the comment form, it says "Posted by at June 9, 2004 07:08 AM".

Do you know a way to fix this?

I imagine any fix would require hacking MT. I haven't looked into it personally because I think MT's developers are aware of it and it wasn't a major issue for me.

Thank you for your fix. I started to go nuts trying to figure out what was wrong before I finally found your message in the support forum!

Thanks for posting this... Someone was nice enough to find your fix for me.

However, I can't seem to find *ANY* in any of the files you mentioned.

My test blog is at http://www.pixeladay.com/home.html.

Any idea?

Hopefully I answered your question in the MT Forums.

A Godsend. Thank you.

This may be a little off topic, but so far this article has been the best source of info on the new commenting system. I installed your module and I was wondering is there a way to change what page loads after a comment is posted? I'd like the form to open just the comment listing again, but I'm not sure what to edit or where. Thanks

Take a look at the paragraph "New addition for popup comments" in the post.

Thank you. Sorry... I'm still learning this TypeKey system.

It looks like you've already got alot on your plate, but should you get around to explaining how this all might work with the simplecomments plug-in, it would be greatly appreciated.

The SimpleComments plugin is for listing comments, not posting them (i.e. TypeKey). The only relation between SimpleComments and TypeKey is that they can be used on the same template - there is no interaction between them.

just wanted to say thanks very much for this fix - it was a lifesaver!

This is a very, very good plugin to have; I hadn't realized going in that changing the form was going to be that much trouble.

I am having a problem though. I signed in here just fine, obviously, but I get "validation failed" when I try to sign in on my own site to test. I had http://www.whinetasting.com/ as my token URL, and after reading other comments and your answers here, I also tried adding http://www.whinetasting.com/cgi-bin/ with no luck, and also changing that to http://www.whinetasting.com/cgi-bin/MT3/ (current MT 3 installation location) also to no avail.

After making the above changes, am I going to have to log out of typekey and then log back in? I'm proud enough of myself that I think I've found all references to static and set them to point to my individual template (can't use PHP includes with the commenting template, unfortunately, and what's the point of having header and footer include files if you have to duplicate that info in other places?); I think I'm really stuck as to why this might happen. Thank you for any suggestions you can make, otherwise this is going to be a great solution.

I guess I should add that the location of all this new stuff is in http://www.whinetasting.com/MT3/ since I didn't particularly want to fool with my live stuff until I got all the bugs worked out on using version 3 properly.

Can anyone comment on whether this module can be successfully modified to work with MT-Approval?

I just installed this module and followed the steps to the letter. I have TypeKey set up, and I get the right sign in/link message, but when I click the link, it doesn't register that I've signed in; when the page refreshes, I get the same "If you'd like to sign in..." message. Cookies are working fine; indeed, I just signed in on this site with no problems. Any ideas?

Actually, your cookies are not working because it appears that your site (journal.gobecky.com) is setting cookies under the www.gobecky.com domain - pages in journal.gobecky.com cannot read cookies stored under www.gobecky.com.

In your template, the javascript code that sets and forgets cookies is missing the HOST variable in them that sets the proper domain for the cookies. I'd suggest replacing the rememberMe() and forgetMe() javascript functions with the following code:

function rememberMe (f) {
    var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', HOST, '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', HOST, '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', HOST, '');

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', HOST);
    deleteCookie('mtcmthome', '/', HOST);
    deleteCookie('mtcmtauth', '/', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';

I just wanted to leave some more praise for this workaround. I really wanted to keep the preview functionality and have styled forms. This was a god-send. Thanks again.

TweezerMan, you need to add:
to your TypeKey sign in/out links.

That code was written for MT 3.0D. It has not been updated for MT 3.01D or any of the MT 3.1x versions (including the current MT 3.15). The code is 9 months old - you use that code at your own risk.

About this Entry

This page contains a single entry by TweezerMan published on May 31, 2004 4:18 PM.

Cookies not remembering properly in MT3D was the previous entry in this blog.

Senate bill prohibiting banks from charging fees to cash paychecks approved is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 6.1.2

MT-Vampire plugin

web hosting by TotalChoice Hosting

Valid XHTML 1.0!
Valid CSS!