HOWTO: Better Remembered Commenters in TXP

In common with most publishing systems, Textpattern helpfully offers to remember your details when you leave a comment. When you next visit, your details are already entered into the textboxes.

This is helpful, but it’s not particularly pretty, is it? It’s not really friendly either. Wouldn’t it be better if, instead of dull textboxes, TXP displayed a nice “Welcome back” message? Of course it would – and that’s what I’m going to show you how to do, today.

This is a hack, so first thing you should do, is back-up your/textpattern/publish/comments.php file.

Done? Ok then, let’s begin. I promise that this is easy-peasy – honest!

Round about line 212 of /textpattern/publish/comments.php, find the following code:

[missing code]

Got it? Then change it to this:

[missing code]

This gives you a new tag for your comments form, and changes the output of others depending on whether the user is remembered or not.

Now add the following to the end of the file:

[missing code]

These two functions give you two new conditional tags: txp:if_remembered andtxp:if_not_remembered – these are included so you can alter the code in your form depending on if the user is remembered or not.

There. Simple. That’s the hard bit done. Honestly, that’s it! All that you have to do now is edit your comment form. As an example, here’s mine:

Note how I use the conditionals to decide whether to display the form labels or not.

That should be everything you need. If you run into problems, let me know. I run on a very hacked copy of Textpattern (obviously), so there may be minor things that I’ve missed out because I thought they were part of another hack or something. As always, your comments are appreciated!