2009
07.29

I’m currently working on a web which uses a contact form. To avoid Spam, I use reCaptcha which is a very good Captcha system (even better than the one I used for the blog comments). You can see it in action in the contact form of this blog.

The problem with the default reCaptcha output is that it does not validates XHTML 1.0 Strict because the use of iframes. But you can change the code at the recaptchalib.php file (available here). This problem persist at the current version (1.10 at this moment).

Replacing the code at lines #122 – #128 with:
[code lang="php"]
return '

';
?>
[/code]
will do the trick ;)

Share
  1. Great job thanks!

    Like or Dislike: Thumb up 0 Thumb down 0

  2. lol.. that’s a pretty rough handling of potential html code ;-)

    My post can be seen here: http://www.finnemann.org/resources/recaptchaXHTMLfix.txt

    (Could also be because of a new recaptcha version perhaps)

    /Torin

    Like or Dislike: Thumb up 0 Thumb down 0

    • I’m not sure.. Maybe the reCaptcha code has change since I posted this code snippet?
      Will check it anyway. Thank you!

      Like or Dislike: Thumb up 0 Thumb down 0

  3. Did you test it with javascript turned off? I’m not sure if it is due to other customization in my recaptcha setup, but the original code had these lines:

    Without them, the user missed a field to post his response in on my site, when not having javascript enabled… The following works for me:
    ————————————————————————
    return ‘

    ‘;
    ————————————————————————
    Thanks for the patch though.!

    /Torin

    Like or Dislike: Thumb up 0 Thumb down 0

  4. oops… here is the code that was supposed to show

    script type="text/javascript"

    Like or Dislike: Thumb up 0 Thumb down 0

  5. :-P Thank you, Thank you! I’ve been looking for this all night. Now I can really tell my client that his site is strict xhtml. Works great.

    For anyone changing the theme using the code on the recaptcha wiki be sure to add the java script type to the script tag. As it will cause an error.

    IE

    :wink:

    Like or Dislike: Thumb up 0 Thumb down 0

  6. Thanks, Kjetil! :wink: I forgot it.
    Fixed.

    Like or Dislike: Thumb up 0 Thumb down 0

  7. There is a </script> missing. Simply add it after the first script tag, and it validates.

    Like or Dislike: Thumb up 0 Thumb down 0

  8. Hi, Steven.

    I’m sure. I’m not using it on this blog contact form (this is done by Deko Boko plugin), but on another site and it validates XHTML strict.

    Perhaps the <script> tag should be closed with </script>. Can you test it?

    Like or Dislike: Thumb up 0 Thumb down 0

  9. Hi Boriel,

    Have you tested this yourself? Your has no closing tag and therefor is causing the page layout to break.

    Like or Dislike: Thumb up 0 Thumb down 0