Jump to content

help with form submission details


toolman

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.