表单重定向成功/失败页面

时间:2014-10-06 09:58:05

标签: javascript php jquery html redirect

我试图让我的表单重定向到成功或失败页面。我已经通过互联网搜索,查看正常的表单重定向甚至是javascript onClick redirect' s。有人可以帮我添加重定向:

HTML:

<!-- ///////////////////////////////////////////////////////////////////////////////// -->
   <!-- CONTACT FORM -->
   <div class="col-lg-6">
   <h1>CONTACT</h1>

         <h3 class="service_h3">Say Hello! Ask something?</h3>               

           <form action="submit_contact.php" id="contactForm">

            <fieldset>
            <div id="result"></div>

               <!-- ///////////////////////////////////////////////////////////////////////////////// -->
               <!-- NAME FIELD -->
                <div class="form-item">
                <label for="name">
                <input type="text" name="name" id="name" placeholder="Enter Your Name" required/>
                </label>
                </div>

               <!-- ///////////////////////////////////////////////////////////////////////////////// -->
               <!-- EMAIL FIELD -->
                <div class="form-item">
                <label for="email">
                <input type="email" name="email" id="email" placeholder="Enter Your Email" required/>
                </label>
                </div>

               <!-- ///////////////////////////////////////////////////////////////////////////////// -->
               <!-- MESSAGE FIELD -->
                <div class="form-item">
                <label for="message">
                <textarea name="message" id="message" placeholder="Your Message" required></textarea>
                </label>
                </div>

               <!-- ///////////////////////////////////////////////////////////////////////////////// -->
               <!-- SUBMIT BUTTON -->
                <div class="form-item">
                <button name="submit" class="submit_btn" action="submit_contact.php" window.open("Done") type="submit">Submit</button>


                </div>

            </fieldset>

           </form>

         </div>

PHP:

<?php

/* Subject and Email Variables*/

$emailSubject = 'Contact Form Submission';
$webMaster = 'no-reply@*Hidden*.com';

/* Gathering Data Variables */

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$messageField = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];
$referred = $_SERVER['HTTP_REFERER'];

$body = <<<EOD
<br><img src="*Hidden*"> <br>GoAerox! Network - Contact Form Submission<hr><br>
<strong>Name:</strong> $nameField <br>
<strong>Email:</strong>  $emailField <br>
<strong>Message:</strong>  $messageField <br><br>
<hr><br><strong>User Details</strong><br>
<strong>IP Address:</strong>  $ip <br>
<strong>Host address:</strong>  $hostaddress <br>
<strong>Browser:</strong>  $browser <br>
<strong>Referred:</strong>  $referred <br>
EOD;

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
**RESULT PAGE**
</html>
EOD;

echo "$theResults";




?>                                

请给出一个由amatuer PHP编码器轻松阅读的答案。注意:我很高兴重定向到实际联系页面上的页面或弹出窗口。只要用户可以看到表单已经提交而没有错误。

2 个答案:

答案 0 :(得分:0)

$ redirecturl =“感谢您的页面网址”
标题('Location:'。$ redirecturl);

使用标题功能重定向到另一个页面。

在邮件功能完成后放置此功能。

答案 1 :(得分:0)

您可以使用以下代码重定向到您的成功或失败页面

    <?php
            $emailSubject = 'Contact Form Submission';
            $webMaster = 'no-reply@*Hidden*.com';

            $nameField = $_POST['name'];
            $emailField = $_POST['email'];
            $messageField = $_POST['message'];
            $ip = $_SERVER['REMOTE_ADDR'];
            $hostaddress = gethostbyaddr($ip);
            $browser = $_SERVER['HTTP_USER_AGENT'];
            $referred = $_SERVER['HTTP_REFERER'];
            $body = <<<EOD
            <br><img src="*Hidden*"> <br>GoAerox! Network - Contact Form Submission<hr><br>
            <strong>Name:</strong> $nameField <br>
            <strong>Email:</strong>  $emailField <br>
            <strong>Message:</strong>  $messageField <br><br>
            <hr><br><strong>User Details</strong><br>
            <strong>IP Address:</strong>  $ip <br>
            <strong>Host address:</strong>  $hostaddress <br>
            <strong>Browser:</strong>  $browser <br>
            <strong>Referred:</strong>  $referred <br>
            EOD;

            $headers = "From: $emailField\r\n";
            $headers .= "Content-type: text/html\r\n";
            $success = mail($webMaster, $emailSubject, $body, $headers);
            header('location:success.php');
    ?>