toolman Posted August 15, 2017 Share Posted August 15, 2017 Hi there, I have the following code which adds a reCAPTCHA to my form, however, I would like to send it to a custom page to display the error or success message. Also, I would like the form to be submitted to my email address with a subject and details of the form completed. How would I do this? This is the code: <form action="footer-contact.php" class="form-horizontal" method="POST"> <div class="form-group"> <label class="col-md-4 control-label">Name:</label> <div class="col-md-6"> <input type="text" class="form-control" name="name" placeholder="Enter Name" required="" /> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Email:</label> <div class="col-md-6"> <input type="text" class="form-control" name="email" placeholder="Enter Email" required="" /> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Message:</label> <div class="col-md-6"> <textarea type="text" class="form-control" name="message" placeholder="Enter Message" required=""></textarea> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Captcha:</label> <div class="col-md-6"> <div class="g-recaptcha" data-sitekey="mySiteKey"></div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-6" class="text-center"> <br/> <input class="btn btn-success" type="submit" name="submit" value="Submit"> </div> </div> </form> <?php if($_SERVER["REQUEST_METHOD"] === "POST") { $recaptcha_secret = "mySecretKey"; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']); $response = json_decode($response, true); if($response["success"] === true){ echo "Form Submit Successfully."; }else{ echo "You are a robot"; } } ?> Any help would be great! Thanks. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 15, 2017 Share Posted August 15, 2017 What is a “custom page”? Why is footer-contact.php not a “custom page”? If you want to send data to an e-mail address, well, then you'll need an e-mail. Quote Link to comment Share on other sites More sharing options...
toolman Posted August 15, 2017 Author Share Posted August 15, 2017 Hi, By custom page I mean like a "thank you" page or "error" page. The footer-contact.php file is the file that contains the PHP code. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 16, 2017 Share Posted August 16, 2017 Sending the user to an error page where they have to manually go back and possibly lose all input doesn't sound particularly user-friendly. The standard approach is to send the data to the script itself (leave out the action attribute altogether) and stay there until all problems have been resolved. Then you can redirect the user to a success page with a Location header. An error page only makes sense as a global webserver setting for the (hopefully rare) case that there's a server-side issue. Quote Link to comment 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.