How to correct captcha integration in th_mailformplus

December 30th, 2008 • typo3, extension, captcha • comments
How to correct captcha integration in th_mailformplus

If you want to use Kaspars/Bernhards captcha extension to meet antispam requirements, you will experience wrong results in captcha image height and width on rendering. Here's a little trick to circumvent this problem.

UPDATE

Since version 4.0.11 of th_mailformplus, the fixed size for the captcha image was removed.

First, create a new PHP script. I choose this method because I want to test it out and eventually later bundle this functionality with some other methods I've already written for the great th_mailformplus extension.

Store the script e.g. in a directory "scripts" underneath the "fileadmin" directory. Use this filename: class.user_thMailformplusExtension.php.

Write a class signature like the following:


class user_thMailformplusExtension
{
  /**
   * 
   */
  public function show_form_postHandling(&$markerArray, &$parentObj)
  {
    // correct captcha extension inclusion -> height attribute is hard coded in th_mailformplus!
    if (t3lib_extMgm::isLoaded('captcha'))
    {
      $markerArray['###CAPTCHA###'] = str_replace('height="100"', 'height="'. intval($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['captcha']['imgHeight']) .'"', $markerArray['###CAPTCHA###']);
      $markerArray['###CAPTCHA###'] = str_replace('width="95"', 'width="'. intval($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['captcha']['imgWidth']) .'"', $markerArray['###CAPTCHA###']);
    }
  }
}

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['th_mailformplus']['tx_thmailformplus_pi1']['show_form'][] = 'fileadmin/scripts/class.user_thMailformplusExtension.php:user_thMailformplusExtension';
PHP

What does this script do? First, the script checks if the captcha extension is loaded. We only support this extension, because others (sr_freecap) renders ugly, unreadable images. Whatever, if this extension is found, the hard coded height and width attributes will be resolved to the settings of the captcha extension which can be changed in the extension manager.

The most important thing is the very last line before the closing php-Tag. This line ensures, that the hooks which are implemented in the th_mailformplus extension will recognize our neat little script.

If all this is done, the very last thing to do is: make it visible for the TYPO3 rendering process via TypoScript configuration. I suggest to declare a includeLibs entry in the root template of your site and add this script to the rendering process:


includeLibs {
  thMailformplusExtension = fileadmin/scripts/class.user_thMailformplusExtension.php
}
TypoScript setup

That's it! You're done! As always: clear your caches and watch the results in a captcha-equipped th_mailformplus form!

Hope this helps. Thanks for comments and improvements.

Comments

    No comments

Leave a comment

Make sure you enter the * required information where indicated. Comments are moderated – and rel="nofollow" is in use. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!