php - How to display a recaptcha error within the submitted form's page? -
i using recaptcha widget on contact form, wondering how able display error user gets on same page instead of going page , displaying error.
you can put form submit on same page, , check post data on php side. check example:
<?php $captcha = $_post['captcha']; if(isset($captcha)) { $captcha_answer = // need put correct captcha answer here if($captcha == $captcha_answer) { // captcha correct, continue. } else { // captcha not correct, display error message. echo '<div style="background-color:red; padding:3px;">your captcha not correct, please try again.</div>'; echo '<form method="post"> <input type="text" name="captcha" value="type captcha here" /> </form>'; // print page again } } else { ?> <form method="post"> <input type="text" name="captcha" value="type captcha here" /> </form> <?php } ?> another option use javascript ajax.
Comments
Post a Comment