MT does not Remember personal info

When entering a comment in a Movable Type powered site, a radio button is available telling you that it is going to ‘Remember personal info’. However, sometimes when you come back to the same site and want to write another comment, all fields are empty. Your personal info has not been saved… 🙁

The problem I described above appears regularly on the Movable Type support forum, and since the answer is always the same, I created this explanation, so I only have to point here to answer the question.

First a small explanation on how the system is supposed to work. If you enter a comment and select the ‘Remember personal info’ radio button, your name, address and URL are stored in a so-called cookie on your computer. This cookie contains the domain of the site, the directory for which the cookie is valid, an expiration date, and of course the stored value. For example, if I post a comment on an entry of this site, a cookie with the name mtcmdhome will be created with the following information:

Name: mtcmdhome Content: http%3A//example.com/ Domain: .jeroensangers.com Path: / Expires: 28-01-2005

This will make sure that the URL I entered (http://example.com/) will be stored for one year, and can be used by any page on the .jeroensangers.com sites.

MT sets this cookie using JavaScript, which you can find in the Individual Entry Archive template. You can find this script at line 29 of the default template.

By default, the script does not specify a path for the cookie, so that the cookie is stored using the path of the individual entry page. So the cookie of this page would only be valid for pages in /2004/01/mt_does_not_remember_personal_info, which is only one page. Since the cookie is not valid for my other pages, the details I filled in when commenting on this page won’t show up in other pages. Note that the default MT installation places all archives in a single directory (e.g. /archives), so this problem does not appear.

If you do place your archives into different directories, you’ll have to need to adjust the JavaScript in the template to fit your situation. The key is that you need to specify the directory for the cookie depending on the set-up of your site. If you have your own domain like I have, you can set it to ‘/’ to be valid for the whole domain. If you use a directory on the domain of your provider (e.g. http://example.com/username/), you can set it to ‘/username’.

To set the directory for the cookies, edit the functions rememberMe and forgetMe in your template. The location for the path has to be inserted between the two apostrophes before HOST. The original code is:

function rememberMe (f) { var now = new Date(); fixDate(now); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); setCookie('mtcmtauth', f.author.value, now, '', HOST, ''); setCookie('mtcmtmail', f.email.value, now, '', HOST, ''); 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 = ''; }

The code for http://example.com/username/ becomes:

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

After making these small changes, the cookie is valid for your whole site, and the details filled in when creating a comment show up on all the pages.

Jeroen Sangers @jeroensangers