Hi All,
Ok, so i've a form on our client site. They say that due to spam they wish to add a re-captcha field. Unfortunately, in doing this, it breaks the design.
What I would therefore like to do, is the user completes the form, clicks submit, then completes a recaptcha as a pop up before being redirected to a thank you page.
Am at a loss though, here's my code if someone can help!
<?php
require_once "/cmsAdmin/lib/viewer_functions.php";
// Get a key from http://recaptcha.net/api/getkey
require_once('recaptchalib_comments.php');
if (preg_match("//", $_SERVER['HTTP_HOST'])) {
$publickey = "";
$privatekey = "";
}
else if (preg_match("/.com/", $_SERVER['HTTP_HOST'])) {
$publickey = "";
$privatekey = "";
}
// process form
if (@$_REQUEST['submitForm']) {
// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['quick_enquiry_name']) { $errorsAndAlerts = "Please fill out all fields\n"; }
if (!@$_REQUEST['quick_enquiry_email']) { $errorsAndAlerts = "Please fill out all fields\n"; }
else if(!isValidEmail(@$_REQUEST['quick_enquiry_email'])) { $errorsAndAlerts = "That email address is not valid\n"; }
if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please fill out all fields\n"; }
if (!@$_REQUEST['recaptcha_response_field']) { $errorsAndAlerts .= "Please enter the two words displayed (this is to stop spam).<br/>"; }
if (@$_REQUEST['recaptcha_response_field']) {
$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) { $errorsAndAlerts .= "Incorrect value for anti-spam validation, please try again.<br/>"; }
$captchaError = $resp->error;
}
$textToConvert = $_REQUEST['enquiry'];
$convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert);
// send email user
if (!$errorsAndAlerts) {
$to = "info@domain.com";
$subject = "Quick Contact";
$email = $_REQUEST['quick_enquiry_email'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
#$headers .= "Content-Type: text/html; charset=utf8\r\n";
$headers .= "From: $email \r\n";
$body = "<strong>Full name</strong>: ". $_REQUEST['quick_enquiry_name'] ."<br />";
$body .= "<strong>Email</strong>: ".$_REQUEST['quick_enquiry_email'] ."<br />";
$body .= "<strong>Enquiry</strong>: $convertedText<br /><br />";
$body .= "The user who sent this message had the IP address <strong>".$_SERVER['REMOTE_ADDR']."</strong><br />";
$message = $body;
// Note: The above line must be flush left or you'll get an error
// This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
// send message
$mailResult = @mail($to, $subject, $message, $headers);
if (!$mailResult) { die("Mail Error: $php_errormsg"); }
//
$errorsAndAlerts = "Thanks! We've sent your email.";
$_REQUEST = array(); // clear form values
}
}
?>
<!-- right quick_contact form -->
<!-- quick_contact_title -->
<div class="rh_quick_contact_title">
<img src="images/rh_quick_enquiry_title.jpg" width="232" height="31" />
</div>
<!-- /quick_contact_title -->
<!-- quick_contact_form -->
<div class="rh_quick_contact_content">
<form method="post">
<input type="hidden" name="submitForm" value="1" />
<?php if (@$errorsAndAlerts): ?>
<div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;">
<?php echo $errorsAndAlerts; ?>
</div>
<?php endif ?>
<table width="213" border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<input name="quick_enquiry_name" type="text" id="quick_enquiry_name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" />
</td>
</tr>
<tr>
<td align="center">
<input name="quick_enquiry_email" type="text" id="quick_enquiry_email" style="width:180px;" value="Email Address..." onclick="clickclear(this, 'Email Address...')" onblur="clickrecall(this,'Email Address...')"/>
</td>
</tr>
<tr>
<td align="center">
<textarea name="enquiry" id="enquiry" value="Enquiry..." onclick="clickclear(this, 'Enquiry...')" onblur="clickrecall(this,'Enquiry...')" style="width:180px;" rows="4"></textarea>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">
Please enter the words below (anti-spam)<br />
<?php echo recaptcha_get_html($publickey, @$captchaError); ?>
</td>
</tr>
<tr>
<td><div align="right">
<input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit">
</div></td>
</tr>
</table>
</form>
</div>
<!-- /quick_contact_form -->
Thanks in advanced