I don't know if this is what you are looking for but the reCaptcha in SugarCRM is used in the login, when you click in the Forgot Password link, below the password field.
By default is off, if you want to activate it, login into Sugar, go to the admin section, then go to the Password Management and in the User Reset Password section you will find the option Enable reCAPTCHA Validations. Once you click on it, two new fields will be shown: public and private key, here is where you add those keys.
Why the keys have to be defined in the admin section?
Because in the login page (where the reCaptcha is used) they obtained the keys through an administration object. In the next PHP code I'll show the way they used.
How do you get those keys?
Go to http://www.google.com/recaptcha sign in or login and by specifying a domain you can have the two keys. (it will generate the two keys for your domain)
Now, about the web to lead form, to be honest, I've never used them but if you want to add the code to use reCaptcha you can find the code in the login.php and login.tpl (located in modules/Users/ ) At the end of the login.php you will find a comment (// RECAPTCHA) below it is the whole code, let me explain it a little more:
PHP Code:
// RECAPTCHA
$admin = new Administration(); // The administration object as I said previously
$admin->retrieveSettings('captcha');
$captcha_privatekey = "";
$captcha_publickey="";
$captcha_js = "";
$Captcha='';
// if the admin set the captcha stuff, assign javascript and div
if(isset($admin->settings['captcha_on'])&& $admin->settings['captcha_on']=='1' && !empty($admin->settings['captcha_private_key']) && !empty($admin->settings['captcha_public_key'])){
$captcha_privatekey = $admin->settings['captcha_private_key'];
$captcha_publickey = $admin->settings['captcha_public_key'];
$captcha_js .="<script type='text/javascript' src='" . getJSPath('include/javascript/sugar_grp1_yui.js') . "'></script><script type='text/javascript' src='" . getJSPath('include/javascript/sugar_grp_yui2.js') . "'></script>
<script type='text/javascript' src='http://api.recaptcha.net/js/recaptcha_ajax.js'></script>
<script>
function initCaptcha(){
Recaptcha.create('$captcha_publickey' ,'captchaImage',{theme:'custom'});
}
window.onload=initCaptcha;
var handleFailure=handleSuccess;
var handleSuccess = function(o){
if(o.responseText!==undefined && o.responseText =='Success'){
generatepwd();
Recaptcha.reload();
}
else{
if(o.responseText!='')
document.getElementById('generate_success').innerHTML =o.responseText;
Recaptcha.reload();
}
}
var callback2 ={ success:handleSuccess, failure: handleFailure };
function validateAndSubmit(){
var form = document.getElementById('form');
var url = '&to_pdf=1&module=Home&action=index&entryPoint=Changenewpassword&recaptcha_challenge_field='+Recaptcha.get_challenge()+'&recaptcha_response_field='+ Recaptcha.get_response();
YAHOO.util.Connect.asyncRequest('POST','index.php',callback2,url);
}</script>";
$Captcha.="<tr>
<td scope='row' width='20%'>".$mod_strings['LBL_RECAPTCHA_INSTRUCTION'].":</td>
<td width='70%'><input type='text' size='26' id='recaptcha_response_field' value=''></td>
</tr>
<tr>
<td colspan='2'><div style='margin-left:2px'class='x-sqs-list' id='recaptcha_image'></div></td>
</tr>
<tr>
<td colspan='2' align='right'><a href='javascript:Recaptcha.reload()'>".$mod_strings['LBL_RECAPTCHA_NEW_CAPTCHA']."</a>
<a class='recaptcha_only_if_image' href='javascript:Recaptcha.switch_type(\"audio\")'>".$mod_strings['LBL_RECAPTCHA_SOUND']."</a>
<a class='recaptcha_only_if_audio' href='javascript:Recaptcha.switch_type(\"image\")'> ".$mod_strings['LBL_RECAPTCHA_IMAGE']."</a>
</td>
</tr>";
$sugar_smarty->assign('CAPTCHA', $Captcha);
echo $captcha_js;
}else{
echo "<script>
function validateAndSubmit(){generatepwd();}
</script>";
}
The main part is the 'if' when it verifies that the reCaptcha is set and if a public and private key are set, is so, then the javascript code will be shown, but if not, the else statement will be used (which is the usually the case since the reCaptcha is, as you remember, off by default)
There's two important things:
1) This code is in a PHP page so you need to pass some variables to a .tpl page (the one that has the html code and it will be shown. Remember, that sugar uses Smarty as the php template to separate the logic from the view, so when you see a tpl file remember that those are Smarty files and the way to send information to them (from php pages) is by calling the assign function in an Sugar_Smarty object) For that reason is that you find the line:
PHP Code:
$sugar_smarty->assign('CAPTCHA', $Captcha);
2) Now if you go at the end of the login.tpl file you will find that the CAPTCHA variable is used:
PHP Code:
<form action="index.php" method="post" name="fp_form" id="fp_form" >
<table cellpadding="0" cellspacing="2" border="0" align="center" width="100%">
<tr>
<td colspan="2" class="login_more">
<div style="cursor: hand; cursor: pointer; display:{$DISPLAY_FORGOT_PASSWORD_FEATURE};" onclick='toggleDisplay("forgot_password_dialog");'>
<IMG src="{sugar_getimagepath file='advanced_search.gif'}" border="0" alt="Hide Options" id="forgot_password_dialog_options">
<a href='javascript:void(0)'>{sugar_translate module="Users" label="LBL_LOGIN_FORGOT_PASSWORD"}</a>
</div>
<div id="forgot_password_dialog" style="display:none" >
<input type="hidden" name="entryPoint" value="GeneratePassword">
<table cellpadding="0" cellspacing="2" border="0" align="center" width="100%" >
<tr>
<td colspan="2">
<div id="generate_success" class='error' style="display:inline;"> </div>
</td>
</tr>
<tr>
<td scope="row" width="30%">{sugar_translate module="Users" label="LBL_USER_NAME"}:</td>
<td width="70%"><input type="text" size='26' id="fp_user_name" name="fp_user_name" value='{$LOGIN_USER_NAME}' /></td>
</tr>
<tr>
<td scope="row" width="30%">{sugar_translate module="Users" label="LBL_EMAIL"}:</td>
<td width="70%"><input type="text" size='26' id="fp_user_mail" name="fp_user_mail" value='' ></td>
</tr>
{$CAPTCHA}
<tr>
<td scope="row" width="30%"><div id='wait_pwd_generation'></div></td>
<td width="70%"><input title="Email Temp Password" class="button" type="button" style="display:inline" onclick="validateAndSubmit(); return document.getElementById('cant_login').value == ''" id="generate_pwd_button" name="fp_login" value="{sugar_translate module="Users" label="LBL_LOGIN_SUBMIT"}"></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
Is the line that it says:
The rest is the html code of the Forgot Password section in the login. Since the CAPTCHA is where the image will be shown, they put it below the field fp_user_mail.
If you need to use the reCaptcha code, just copy the javascript code and the CAPTCHA variable use it in the tpl page you want the reCaptcha to be display.
If there is anything I can help, just tell me.
Regards.
Bookmarks