Hack to use the cb Captcha on the Joomla Contact form
This worked for me, your experience may vary.
Joomla version 1.0.12
CB version: 1.0.2
CB Captcha plugin version: 1.0 (14.Feb.2007)
Files to hack:
/components/com_comprofiler/plugin/user/plug_cbcaptcha/cb.captcha.php
/components/com_contact/contact.html.php
/components/com_contact/contact.php
1. cb.captcha.php
Since we're using the plugin code outside of the CB plugin framework we need to put all the $_PLUGINS->registerFunction() calls in an if statement like so:
[code:1]if ($_PLUGINS) {
$_PLUGINS->registerFunction( 'onBeforeRegisterForm', 'onBeforeRegisterForm', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onBeforeUserRegistration','onBeforeUserRegistration', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onLostPassForm', 'onLostPassForm', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onLostPassForm', 'onLostPassFormB', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onBeforeNewPassword', 'onBeforeNewPassword', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onAfterEmailUserForm', 'onAfterEmailUserForm', 'getcaptchaTab' );
$_PLUGINS->registerFunction( 'onBeforeEmailUser', 'onBeforeEmailUser', 'getcaptchaTab' );
}
[/code:1]
2. contact.html.php
Around line 685 (after the contact text textarea) insert this code:
[code:1]// hack - added CB captcha to the contact form
require_once($mosConfig_absolute_path.'/administrator/components/com_comprofiler/plugin.class.php');
require_once($mosConfig_absolute_path.'/components/com_comprofiler/plugin/user/plug_cbcaptcha/cb.captcha.php');
$cbCaptcha = new getcaptchaTab;
$CaptchaImage = $cbCaptcha->_getHTMLcaptcha();
echo "<br />\n" .$CaptchaImage. "<br />\n";
echo " <label for=\"security_code\">" . _UE_CAPTCHA_Label . ":</label>\n";
echo " <br /><input class=\"inputbox\" type=\"text\" name=\"".$cbCaptcha->_getPagingParamName("captcha"«»)."\" id=\"security_code\" value=\"\" size=\"20\" />\n";
// end hack
[/code:1]
3. contact.php
At the top of the file, before the switch statement insert:
[code:1]// hack start a session here for the security images
if ( ! session_id() ) {
session_start();
}
// end hack[/code:1]
Then around line 435 after:
[code:1]if ( !$email || !$text || ( JosIsValidEmail( $email ) == false ) ) {
mosErrorAlert( _CONTACT_FORM_NC );
}[/code:1]
and before:
[code:1] $prefix = sprintf( _ENQUIRY_TEXT, $mosConfig_live_site );
[/code:1]
Insert:
[code:1]// RP hack captcha check
if ( ! (($_SESSION == mosGetParam($_REQUEST,"captcha"«»)) && (!empty($_SESSION)) ) ) {
mosErrorAlert( "Invalid Security Code" );
}
// end hack
[/code:1]
That's it - enjoy a secure contact form.
Post edited by: phlux0r, at: 2007/04/10 04:08