Jump to content

validate form with php, if all ok then post data


jarvis

Recommended Posts

Hi All,

 

Probably very simple but can't work it out. I've the following form

<form method="post" action="sendEmail.php">
<?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 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>	
<input type="hidden" name="submitForm" value="1" />
<input type="hidden" name="quick_enquiry_name" value="<?php echo htmlspecialchars($_POST['quick_enquiry_name']); ?>" />
<input type="hidden" name="quick_enquiry_email" value="<?php echo htmlspecialchars($_POST['quick_enquiry_email']); ?>" />
<input type="hidden" name="enquiry" value="<?php echo htmlspecialchars($_POST['enquiry']); ?>" />		
</form>

Some values a past in from a previous form.

 

What I'm trying to do, is the above form has a recaptcha, sO I need to verify the input from here first, if it's ok, then process the form which sends an email using sendEmail.php. My validation is below:

<?php

  
// Get a key from http://recaptcha.net/api/getkey
require_once('recaptchalib_comments.php');
if (preg_match("/domain.com/", $_SERVER['HTTP_HOST'])) {
	$publickey  = "";
	$privatekey = "";
}
else if (preg_match("/domain.co.uk/", $_SERVER['HTTP_HOST'])) {
	$publickey  = "";
	$privatekey = "";
}  

  if (@$_REQUEST['submitForm']) {
  $errorsAndAlerts = "";
  
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;
  	}	  
  
  }

?>

At the moment, blank fields in my recaptcha or the wrong words still process the form & therefore email as I can't work out how to test the form first.

 

Any help is much appreciated!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.