Hi there,

I posted another thread earlier about Recaptcha. I'm trying to implement a recaptcha into a form on my client's website. However, when I add this code (below) to the correct position in the page's source code, it's showing up with a syntax error on the line starting require_once('recaptchalib.php'). If I "put" it it says that there is an error when I view it on the web (Parse error: syntax error, unexpected T_STRING in /home/etcetc........contact2.php on line 250). I've tried removing the " around recaptchalib.php which gets rid of the error, but when put the recaptcha doesn't show up.

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

The full code of my page is:

<?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 -->
 <script type="text/javascript">
 var RecaptchaOptions = {
    theme : "white"
 };
 </script>
			
<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 colspan="2" align="center"> 
	  <?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
</th>
</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);

?>

Any help would be awesome!

You should put this before line 153:

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

And change lines 249-253 to:

' . $captcha . '

You are trying to execute code within a string, that won't work.

Cheers for the reply. I've tried that, and it's got rid of the syntax error, but nothing is displaying on the page at all now... it's just a blank page - www.electrix.co.uk/contact2.php

Any idea?

Working now. Just struggling with the verify page now.

Ok, so the verify page is continuously thinking that I'm entering the wrong information. I have it set up to go to google.co.uk if it's an incorrect captcha and a different page if correct (just for testing purposes), but for some reason it always thinks it's the wrong captcha.

Can you see anything wrong with either of these bits of code to suggest why this would be happening?

Firstly the contact page (www.electrix.co.uk/contact2.php):

<?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());

require_once('recaptchalib.php');
$publickey = "6LeiEskSAAAAAHnRLNDQS31tOEzWlGQzOabB8i_R"; // you got this from the signup page
$captcha = recaptcha_get_html($publickey);
$page_content = mysql_fetch_array($result);
$content .= $page_content['content'];
$content .= '

<!-- End Dynamic Content -->
 <script type="text/javascript">
 var RecaptchaOptions = {
    theme : "white"
 };
 </script>
			
<div class="boxheader">'.$sb->dt('Enquiry Form').'</div>
<form style = "margin: 0px" name="enquiries" method="post" onSubmit="return verifyEnEnquiry(this);" action="verify.php">
</div>
<table style = "margin-left: 11px; width: 383px">
<input type="hidden" name="Location" value="verify.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 colspan="2" align="center"> 
'. $captcha .'
</th>
</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);

?>

& www.electrix.co.uk/verify.php

<?php
  require_once('recaptchalib.php');
  $privatekey = "myprivatekey";
  $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
	header("Location: http://www.google.com");
  } else {
    header("Location: contact-complete2.php");
  }
  ?>
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.