hindu times 0 Junior Poster

Hi there,

I've been given the task of adding a Google recaptcha to a form on this website I'm working on. I'm not really familiar with the code that I've been given to edit, so I was wondering if anyone can help me.

Basically, the "contact" page looks like this (below), but I need to add a recaptcha to the point in the code that says RECAPTCHA:

<?php require('sbsquared.class.php'); ?>
<?php

if(!empty($_GET['lang'])) {

	switch($_GET['lang']) {
	
		case 'fr':
		
			setlocale(LC_ALL, 'fr_FR.utf8');		
			$_SESSION['language'] = 'fr';
			break;
			
		case 'us':
		
			setlocale(LC_ALL, 'en_EN.utf8');						
			$_SESSION['language'] = 'us';
			break;
		
		case 'eu':
		
			setlocale(LC_ALL, 'en_EN.utf8');						
			$_SESSION['language'] = 'eu';
			break;
			
		case 'de':

			setlocale(LC_ALL, 'de_DE.utf8');		
			$_SESSION['language'] = 'de';
			break;
			
		default:
		
			setlocale(LC_ALL, 'en_EN.utf8');				
			$_SESSION['language'] = 'en';
			
	}
}

$sb = New SBSquared;
$content = '<div id="main_middle">

<style>
#sbtbtn{
	margin:0;
	padding: 0;
	list-style:none;
	}

#sbtbtn a{
	margin-top: 2px;
	background: #80b0fc url(./images/right_arrow_light.gif) top right no-repeat;
	display:block;
	padding: 2px;
	font-family:arial;
	color:#fff;	
	text-decoration:none;
	font-size:8pt;
	font-weight:400;
	margin-right:5px;
	width:143px;
	}
	
#sbtbtn a.darkblue{
	margin-top: 2px;
	background: #005ff8 url(./images/right_arrow_dark.gif) top right no-repeat;
	display:block;
	padding: 1px;
	font-family:arial;
	color:#fff;	
	text-decoration:none;
	font-size:110%;
	font-weight:400;
	margin-right:10px;
	width:130px;
	padding-left: 2px;
	}
</style>
<script language = "javascript">

function verifyEnEnquiry(theform) {
	var my_message = "default";
	if(document.enquiries.FullName.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Full Name').'");
		//return false;	
	} else
	if(document.enquiries.Company.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Company Name').'");
		//return false;	
	} else	
	if(document.enquiries.Email.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Email ').'");
		//return false;	
	} else	
	if(document.enquiries.address_4.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your City').'");
		//return false;	
	} else	
	if(document.enquiries.Enquiry.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Enquiry ').'");
		//return false;	
	} else	
	if(document.enquiries.JobTitle.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Job Title').'");
		//return false;	
	} else
	if(document.enquiries.country.selectedIndex == 0)
	{
		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Country').'");
		//return false;
	} else	
	if(document.enquiries.address_1.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Address').'");
		//return false;	
	} else
	if(document.enquiries.Postcode.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Postcode').'");
		//return false;	
	}
	else {

		//return true;
		document.enquiries.submit();
	}
	//alert(my_message);
}

</script>

<!-- Start Dynamic Content -->

';

$conn = $sb->openConnection();
if($_SESSION['language'] == "eu") {
	$lang = "en";
}
else {
	$lang = $_SESSION['language'];
}

$sql = "SELECT * FROM `content_pages` WHERE `page` = 'contact' AND `lang` = '".$lang."'";
$result = mysql_query($sql, $conn) or die(mysql_error());

$page_content = mysql_fetch_array($result);
$content .= $page_content['content'];
$content .= '

<!-- End Dynamic Content -->
			
<div class="boxheader">'.$sb->dt('Enquiry Form').'</div>
<form style = "margin: 0px" name="enquiries" method="post" onSubmit="return verifyEnEnquiry(this);" action="contact-complete.php">
</div>
<table style = "margin-left: 11px; width: 383px">
<input type="hidden" name="Location" value="en_contact-complete.php">
<tr>
<style>
	th { 
		 padding-left: 8px;
		}
</style>
<th>'.$sb->dt("Enquiry Type *").'</th>
<td align = "right">
<select name="EnquiryType" style="font-size:100%;width:202px;border:1px solid #808080" />
<option value="Sales">'.$sb->dt('Sales').'</option>
<option value="Technical">'.$sb->dt('Technical').'</option>
<option value="Quotations">'.$sb->dt('Quotations').'</option>
<option value="General Enquiry">'.$sb->dt('General Enquiry').'</option>
<option value="Literature Request">'.$sb->dt('Literature Request').'</option>
</select>
</td>
</tr>
<tr>
<th>'.$sb->dt("Full Name *").'</th>
<td align = "right"><input name="FullName" type="text" id="FullName" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Company *").'</th>
<td align = "right"><input name="Company" type="text" id="Company" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Job Title *").'</th>
<td align = "right"><input name="JobTitle" type="text" id="JobTitle" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Address *").'</th>
<td align = "right"><input type="text" name="address_1" style="width:200px" /></td>
</tr>
<tr>
<th></th>
<td align = "right"><input type="text" name="address_2" style="width:200px" /></td>
</tr>
<tr>
<th></th>
<td align = "right"><input type="text" name="address_3" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("City *").'</th>
<td align = "right"><input type="text" name="address_4" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Postal Code *").'</th>
<td align = "right"><input name="Postcode" type="text" id="Postcode" style="width:200px" /></td>
</tr>
<th>'.$sb->dt("Country *").'</th>
<td align = "right"> <select name="country" style="font-size:90%;width:202px;border:1px solid #808080">
'.genCountryList().'
</select></td>
</tr>
<tr>
<th>'.$sb->dt("Telephone Number").'</th>
<td align = "right"><input name="Telephone" type="text" id="Telephone" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Email *").'</th>
<td align = "right"><input name="Email" type="text" id="Email" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Fax Number").'</th>
<td align = "right"><input name="Fax" type="text" id="Fax" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Website").'</th>
<td align = "right"><input name="Website" type="text" id="Website" style="width:200px" /></td>
</tr>
<tr>
<th>'.$sb->dt("Enquiry *").'</th>
<td align = "right"><textarea name="Enquiry" rows="8" style="font-size:90%;width:200px;border:1px solid #808080; font: 9pt arial"></textarea></td>
</tr>
<!--<tr>
<th>Send a File (Max. 2Mb)</th>
<td align = "right"><input name="FileUpload" type="file" id="FileUpload" style="width:160px" /></td>
</tr>-->
<tr>
<th>RECAPTCHA</th>
<!--<td align = "right"></td>-->
</tr>
<tr>
<th>&nbsp;</th>
<td>&nbsp;</td>
</tr>
</table>
<center><table width = "100%" style = "border: 0px; width: 395px"><tr><td align = "right">
<ul id="sbtbtn">
<li><a style = "margin-top: 5px; text-align: left; font: 8pt arial;" href="Javascript:verifyEnEnquiry(document.enquiries);" title="'.$sb->dt('Send Enquiry').'" class="darkblue">'.$sb->dt('Submit Enquiry').'</a></li>
</ul>
</td></tr></table>
<p style="text-align:right !important">
<!--<input name="submit"  style="border:none" type="image" src="./img/en/btn-sendenquiry.gif" title="'.$sb->dt("Send Enquiry").'">-->
</p>
</form>
</p>
<p><em>'.$sb->dt('*Mandatory fields').'<br />
</em></p>
';

$content .= '</div>';

echo pageHeader($sb);
echo pageContent($sb, $content);
echo pageFooter($sb);

?>

I've tried adding in the below code to the point in the code where it says recaptcha, with no luck (obviously including our own public key):

<?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>

I've also added this to our contact-complete.php page:

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

Any ideas where I'm going wrong, or if using the PHP method is in fact the best way to go?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.