Where the heck do I put reCaptcha php on MY existing form? -



Where the heck do I put reCaptcha php on MY existing form? -

i'm trying implement recaptcha existing contact form, , have nail snag (notice used word exactly) place server side php code within page.

i've added required php within form right public key (and added private key server side php).

i have validation php form @ top of same page form on.

existing validation code follows:

<?php // set email variables $email_to = 'myemailishere'; $email_subject = 'my enquiry title here'; // set required fields $required_fields = array('fullname','email','comment'); // set error messages $error_messages = array( 'fullname' => 'please come in name.', 'email' => 'please come in valid email.', 'comment' => 'please come in message.' ); // set form status $form_complete = false; // configure validation array $validation = array(); // check form submittal if(!empty($_post)) { // sanitise post array foreach($_post $key => $value) $_post[$key] = remove_email_injection(trim($value)); // loop required fields , create sure match our needs foreach($required_fields $field) { // field has been submitted? if(!array_key_exists($field, $_post)) array_push($validation, $field); // check there info in field? if($_post[$field] == '') array_push($validation, $field); // validate email address supplied if($field == 'email') if(!validate_email_address($_post[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // prepare our content string $email_content = 'new website comment: ' . "\n\n"; // simple email content foreach($_post $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok send email mail($email_to, $email_subject, $email_content); // update form switch $form_complete = true; } } function validate_email_address($email = false) { homecoming (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? true : false; } function remove_email_injection($field = false) { homecoming (str_ireplace(array("\r", "\n", "%0a", "%0d", "content-type:", "bcc:","to:","cc:"), '', $field)); } ?>

and form code this:

<div id="mainform"> <?php if($form_complete === false): ?> <form autocomplete="off" action="index.php#contact" method="post" id="comments_form"> <div class="row"> <div class="label">your total name</div><!---end label---> <div class="input"> <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_post['fullname'])? $_post['fullname'] : ''; ?>" /><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?> </div><!---end input---> </div><!---end row---> <div class="row"> <div class="label">your email address</div><!---end label---> <div class="input"> <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_post['email'])? $_post['email'] : ''; ?>" /><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </div><!---end input---> </div><!---end row---> <div class="row"> <div class="label">your number? (if you'd call)</div><!---end label---> <div class="input"> <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_post['telephone'])? $_post['telephone'] : ''; ?>" /> </div><!---end input---> </div><!---end row---> <div class="row"> <div class="label">your message</div><!---end label---> <div class="input"> <textarea id="comment" name="comment" class="mess"><?php echo isset($_post['comment'])? $_post['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?> </div><!---end input---> </div><!---end row---> <div class="row"> <div class="label">prove you're human</div><!---end label---> <?php require_once('recaptchalib.php'); $publickey = "your_public_key"; // public key omitted purpose of stackeroverflow echo recaptcha_get_html($publickey); ?> </div><!---end row---> <div class="submit"> <input type="submit" id="submit" name="submit" value="send message" /> </div><!---end submit---> </form> <?php else: ?> <p>thank you, we've received message.</p> <?php endif; ?> </div><!---end mainform--->

so...where stick code (as in integrate code existing validation php)?????:

<?php require_once('recaptchalib.php'); $privatekey = "your_private_key"; $resp = recaptcha_check_answer ($privatekey, $_server["remote_addr"], $_post["recaptcha_challenge_field"], $_post["recaptcha_response_field"]); if (!$resp->is_valid) { // happens when captcha entered incorrectly die ("the recaptcha wasn't entered correctly. go , seek again." . "(recaptcha said: " . $resp->error . ")"); } else { // code here handle successful verification } ?>

hope makes sense , can help?

php forms recaptcha

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -