I hope someone may help me with the following issue. I want to create a new page in WordPress (i.e. http://www.example.com/get-in-touch/thanks)

The reason for this is when the contact form is filled in on http://www.example.com/get-in-touch it doesn’t redirect to another page.

By creating the thank you page, when the button is submitted it will redirect in order to track the amount of people that fill in the contact form so we see what is working in an AdWords campaign.

I have found a piece of code (wp_redirect(get_bloginfo(‘wpurl’).’/your-thank-you-page/’);
exit;)
that is suggested but I’m unsure how this will work or where to fit it into the code?

I’ve included the code below for the contact form……

I appreciate any suggestions !!!!!!

==============================================================================

<?php
/*
* Template Name: Contact Form
*/
$nameError = __( 'Please enter your name.', 'stag' );
$emailError = __( 'Please enter your email address.', 'stag' );
$emailInvalidError = __( 'You entered an invalid email address.', 'stag' );
$commentError = __( 'Please enter a message.', 'stag' );
$errorMessages = array();
if(isset($_POST['submitted'])){
    if(trim($_POST['contactName']) === '') {
        $errorMessages['nameError'] = $nameError;
        $hasError = true;
    } else {
        $name = trim($_POST['contactName']);
    }
    if(trim($_POST['email']) === '')  {
        $errorMessages['emailError'] = $emailError;
        $hasError = true;
    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST['email']))) {
        $errorMessages['emailInvalidError'] = $emailInvalidError;
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }
    if(trim($_POST['comments']) === '') {
        $errorMessages['commentError'] = $commentError;
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['comments']));
        } else {
            $comments = trim($_POST['comments']);
        }
    }
    if(!isset($hasError)) {
        $emailTo = stag_get_option('general_contact_email');
        if (!isset($emailTo) || ($emailTo == '') ){
            $emailTo = get_option('admin_email');
        }
        $subject = '[Contact Form] From '.$name;
        $body = "Name: $name nnEmail: $email nMessage: $comments nn";
        $body .= "--n";
        $body .= "This mail is sent via contact form on ".get_bloginfo('name')."n";
        $body .= home_url();
        $headers = 'From: '.$name.' <'.$email.'>' . "rn" . 'Reply-To: ' . $email;
        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
}
?>
<?php } else { ?>
<?php get_header(); ?>
<!--BEGIN #primary .hfeed-->
<div id="primary" class="hfeed" role="main">
<?php while(have_posts()): the_post(); ?>
    <?php stag_page_before(); ?>
    <!--BEGIN .hentry-->
    <article <?php post_class(); ?>>
    <?php stag_page_start(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
        <!-- BEGIN .entry-content -->
        <div class="entry-content">
            <?php
                the_content( __('Continue Reading', 'stag') );
                wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'stag').'</strong> ', 'after' => '</p>', 'next_or_number' => 'number'));
            ?>
        <!-- END .entry-content -->
        </div>
    <?php stag_page_end(); ?>
    <!--END .hentry-->
    </article>
    <?php stag_page_after(); ?>
<?php endwhile; ?>
<h5 style="font-size: 130% !important" id="reply-title">Send us a message</h5>
<?php if(isset($emailSent) && $emailSent == true) { ?>
    <div class="stag-alert accent-background">
        <p><?php _e('Thanks, your email was sent successfully.', 'stag') ?></p>
    </div>
<form action="<?php the_permalink(); ?>" id="contactForm" class="contact-form" method="post">
    <div class="grids">
        <p class="grid-6">
            <label for="contactName"><?php _e('Your Name', 'stag') ?></label>
            <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>">
        </p>
        <p class="grid-6">
            <label for="email"><?php _e('Your Email', 'stag') ?></label>
            <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>">
        </p>
    </div>
    <p>
        <label for="commentsText"><?php _e('Your Message', 'stag') ?></label>
        <textarea rows="8" name="comments" id="commentsText" ><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
    </p>
    <p class="buttons">
        <input type="submit" id="submitted" class="accent-background contact-form-button" name="submitted" value="<?php _e('Send Message', 'stag') ?>">
    </p>
</form>
<?php } ?>
<!--END #primary .hfeed-->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Read more here: PHP code to redirect contact form to thank you page


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: