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 (780) ) ( 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 )
$task = mosGetParam( $_REQUEST, 'task', '' );
$mySobi_id = $mySobi->id ;</span></em>
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 )
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: Joomla, Sobi2, Sobi2 Captcha
Trackback URL: http://www.website-ideas.co.uk/2009/03/19/captcha-for-joomla/trackback/


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 ”?
OLIVER
April 18, 2010 at 1:03 pm
It doesnt work? I cant understand where to put the script
Perus
April 19, 2010 at 12:05 pm
Font File?
admin
May 16, 2010 at 8:02 pm
@ olvier Script gets copied into your root folder
naseem sarwar
May 19, 2010 at 11:43 am
hi i want to add captcha but i couldnt understande the code example.
let me explain the issues i am having.
1- where to put the script files? in joomla root folder or in joomla/component/sobi2??
2- why to put that code in sob2.details.tmpl ok for some reason i put that code. but there is another code sinppt and and whole fucntion. where to put that in sob2.details.tmpl or sobi2.entry.php
3- where to put the captcha what if i want to add in entry form?
4- in which file i need to put that captcha function into.
please help me out cuase this is the only solution but its not very clear.
admin
May 22, 2010 at 6:07 am
Hi Naseem
1) In the Root of joomla
2)first ask yourself where you want to use a captcha form. in this case it was use in the details template as a enquiry form. In short what form to you want to protect?
3) Captcha stays in root, but just copy code sniplet in your from.tmpl
4) The file where you want the form to display