March 19, 2009

Captcha For Joomla 1.5.x and integration with Sobi2

OK so we finally managed to crack this bad boy for Joomla 1.5.9 . This script allows users to add a Captcha form to there Sobi2 contact page, helping the prevention of spam.  Snake was kind enough to modify and donate this script to us. This Captcha script can be used for any component in Joomla 1.5.x. If you need help setting it up please use our forum and we will assist with the setup and integration into your components. But this should be easy to setup.

This specific demo will show you how to set it up using joomla 1.5 and Sobi2. I’ve attached the files to be downloaded from here.

Firstly you need to download the Font file and Capctha file ( Download Here: Captcha (575) ) ( This script is built of the one from Simon Jarvis ).  Copy these two files into your root folder. Then open your details template  “sobi2.details.tmpl” and copy and paste the code below. ( please note if you wish to use this function else where, you can ignore the sobi2.details.tmpl and add the form to your component of choice.

For Sobi2 Only ( Testing done in legacy mode )

$link = sefRelToAbs(”index.php?option=com_sobi2&sobi2Task=sobi2Details&catid={$catid}&sobi2Id={$mySobi_id}&Itemid=2″);
$task = mosGetParam( $_REQUEST, ‘task’, ” );
$mySobi_id = $mySobi->id ;


switch ($task) {
case 'email' :
emaillisting($mySobi_id);
}

function emaillisting($mySobi_id) {
global $database, $mainframe;
global $mosConfig_live_site, $mosConfig_mailfrom, $mosConfig_fromname;

$directory_email = mosGetParam( $_POST, ‘directory_email’, ” );
$directory_name = mosGetParam( $_POST, ‘directory_name’, ” );
$v_firstname = mosGetParam( $_POST, ‘name’, ” );
$v_email = mosGetParam( $_POST, ‘email’, ” );
$v_telephone = mosGetParam( $_POST, ‘telephone’, ” );
$v_comments = mosGetParam( $_POST, ‘comments’, ” );
$v_province = mosGetParam( $_POST, ‘province’, ” );
$number = intval( mosGetParam( $_POST, ‘number’, 0 ) );
$othernumber = intval( mosGetParam( $_POST, ‘othernumber’, 0 ) );
$sum = intval( mosGetParam( $_POST, ’sum’, 0 ) );
$DIRECTORY_CONTACT_LETTER=(”
Name: %s

Email: %s

Telephone: %s

Province: %s

Message: %s”);
$query_text = sprintf($DIRECTORY_CONTACT_LETTER, $v_firstname, $v_email, $v_telephone, $v_province, $v_comments, $mosConfig_fromname );

//$session =& JFactory::getSession(’captcha_word’);
$session =& JFactory::getSession();
$code = $session->get(’captcha_word’);
if(($code == $_POST['captcha_word']) && (!empty($code)) ) {

$success = mosMail( $email, $mosConfig_fromname , $directory_email, “yourdomain.com Website Enquiry”, $query_text, 0, null,null,null,$v_email,$v_firstname );
$success = mosMail( $email, $mosConfig_fromname , $mosConfig_mailfrom, “Copy of yourdomain.com Website Enquiry for ” . $directory_name, $query_text, 0, null,null,null,$v_email,$v_firstname );

mosRedirect(”index.php?option=com_sobi2&sobi2Task=sobi2Details&sobi2Id=$mySobi_id”, “Message sent successfully..”);

} else {
mosRedirect(”index.php?option=com_sobi2&sobi2Task=sobi2Details&sobi2Id=$mySobi_id”, “Message sending failed. Please insert the correct details in security box..”);
}

}

?>

Then you need to add the form of your choice, here is one that we made. ( change the fields to suit your needs )

<form id=”enquire” onsubmit=”alert(document.getElementById(’id_one’).value); return false;” action=”<?php echo sefRelToAbs( ‘index.php?option=com_sobi2&sobi2Task=sobi2Details&sobi2Id=’. $mySobi->id ); ?>”
method=”post” name=”emailForm” target=”_top” id=”emailForm”>
<label class=”style6″>Name:</label><br />
<input name=”name” type=”text” size=”20″ />
<br />
<label class=”style6″>Email:</label><br />
<input name=”email” type=”text” size=”20″ />
<br />
<label class=”style6″>Telephone number:</label><br />
<input name=”telephone” type=”text” size=”20″ />
<br />
<label class=”style6″>Province:</label><br />
<input type=”text” name=”province” id=”province” />
<br />
<label class=”style6″>Message:</label><br />
<textarea name=”comments” cols=”30″ rows=”5″></textarea>
<br />
<img src=”CaptchaSecurityImages.php” />
Security Code:
<input id=”captcha_word” name=”captcha_word” type=”text” />
<br />
<input type=”submit” name=”Submit” value=”Submit” />
<input type=”hidden” name=”task” value=”email” />
<input type=”hidden” name=”directory_email” value=”<?php echo $mySobi->customFieldsData['field_email']; ?>” />
<input type=”hidden” name=”directory_name” value=”<?php echo $mySobi->customFieldsData['field_contact_person']; ?>” />
<input type=”hidden” name=”number” value=”<?php echo $number; ?>” />
<input type=”hidden” name=”othernumber” value=”<?php echo $othernumber; ?>” />
</form>

If you wish to use the code above you need to alter it a bit to suit the component needs. The basics you will need is a simple function and a form:

function form () {
global $database, $mainframe;

//$session =& JFactory::getSession(’captcha_word’);
$session =& JFactory::getSession();
$code = $session->get(’captcha_word’);
if(($code == $_POST['captcha_word']) && (!empty($code)) ) {

echo “Great Success, very nice”;

} else {
echo “wrong code”;
}

}

?>

Please don’t forget to add your form. The jfactory frame works had to be added to the function in order to make it work. For Joomla 1.5 sessions work differently to Joomla 1.0.

Feel free to use our forum for support, Snake and the moderaters will assist there.

Written by: admin

Filed Under: Joomla, Sobi2, Tutorials, Website Tools

Tags: , ,

Trackback URL: http://www.website-ideas.co.uk/2009/03/19/captcha-for-joomla/trackback/

Comments

  • puho ferenc

    August 23, 2009 at 8:59 pm

    Not understand. Why details.tmpl? Why not add entry form tmpl?

  • puho ferenc

    August 23, 2009 at 9:06 pm

    php open tag is not necessary?

  • Andre

    September 21, 2009 at 4:14 am

    Help, note found script, problem ” ou ” ou ”?

Leave a reply

* means field is required.

*

*