Hi there,
I'm currently adding in a recaptcha to a contact form that I didn't create in the first place, so I've been tentatively working my way around it. For some reason though, every time I complete my form, no matter whether the captcha I entered was right or not, it's coming up with the "incorrect response" (for the time being I have set google.co.uk as the "incorrect captcha" response, just for testing purposes). So it goes to google.co.uk every time I press submit.
Over the in PHP forum, we've established that it is not something wrong with the Recaptcha code, but more likely something interfering with the code... maybe some Javacript?
I've put all the code for the two pages below. Hope you can help! Please bear in mind that I am pretty much a novice with this stuff and just working my way through tutorials and stuff, so any help would be great.
Here is the code for the 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> </th>
<td> </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);
?>
And here is the code for the verify.php:
<?php
require_once('recaptchalib.php');
$privatekey = "6LeiEskSAAAAAHy701oWiFVDXf5YJhRKiRRQgnqH";
//echo "<pre> _POST: =========\n";
//print_r($_POST);
//print_r($_SERVER);
//echo "\n=========\n</pre>";
$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");
}
?>