February 17, 2008

Dave, your forms are EVIL!

A while ago, I got this email from a friend of mine:
i left a long comment on your starbucks entry, but i got a character wrong in your CAPTCHA, and it told me to click the "back" button and try again. however, when i did that, all the entries in the form were BLANK! I LOST MY COMMENT! AIEEEE!!!!!
This is a problem, because I don't like evil in any form. Particularly in my forms. I've been really busy, but spent about thirty minutes poking around at the bBlog internals (looks I chose a bad horse: the bBlog project seems to have died!) and made the field values sticky on an error with the captcha submission.

If you are interested in the changes, here is a diff file that you can apply via patch: patch -b bBlog.class.php bBlog.captcha.diff against an unmodified version 0.7.6 bBlog.class.php from the bBlog install.

Once that is done, you have to modify your template to add value="{$commentFieldPosterXXX}" where XXX is some value. The only exception is {$commentreplytitle} which remains the same.

Here is the relevant portion from my template:

<div class="formleft">Comment Title</div>
<div class="formright"><input name="title" size="80" type="text" id="title" value="{$commentreplytitle}"/></div>
<div class="clear"> </div>
<div class="formleft">Your Name: </div>
<div class="formright"><input name="name" size="80" type="text" id="author" value="{$commentFieldPosterName}"/></div>
<div class="clear"> </div>
<div class="formleft">Email Address: </div>
<div class="formright"><input name="email" size="80" type="text" id="email" value="{$commentFieldPosterEmail}"/>
          Make Public? <input class="checkbox" name="public_email" type="checkbox" id="public_email" value="1" checked=\
"checked"/></div>
<div class="clear"> </div>
<div class="formleft">Website: </div>
<div class="formright"><input name="website" size="80" type="text" id="url" value="{$commentFieldPosterWebsite}" />
          Make Public? <input class="checkbox" name="public_website" type="checkbox" id="public_website" value="1" chec\
ked="checked" /></div>
<div class="clear"> </div>
<div class="formleft"><img src="/randomImage.php" alt="verification image"><br>Image verification:</div>
<div class="formright"><font color="red">{$commentFieldError}</font></div>
<div class="formright"><input name="verification" type="text" id="verification" /></div>
<div class="clear"> </div>
<div class="formleft">Comment:</div>

<div class="formright"><textarea name="comment" cols="80" rows="10" wrap="VIRTUAL" id="text">
{$commentFieldPosterComment}</textarea></div>
Of course, you also need to follow the relevant directions in my original post on adding a captcha for comment protection in bblog. But it looks like things are working well for me here.

The diff patch is here.


Comments

Provide your email address when commenting and Gravatar will provide general portable avatars, and if you haven't signed up with them, a cute procedural avatar with their implementation of Shamus Young's Wavatars.

Comments have now been turned off for this post