jarvis Posted March 15, 2010 Share Posted March 15, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/195285-validate-form-with-php-if-all-ok-then-post-data/ Share on other sites More sharing options...
jarvis Posted March 15, 2010 Author Share Posted March 15, 2010 Ideally I dont want to use javascript and php to validate and process, am fast running out of ideas on this one though. Is this the only options available? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/195285-validate-form-with-php-if-all-ok-then-post-data/#findComment-1026261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.