如何重定向到 PHP 中的感谢页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15800785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:59:58  来源:igfitidea点击:

How can I redirect to a thank you page in PHP

phphtmlformsredirectcontact

提问by Pir Fahim Shah

Ok, so I would like to redirect to a thank you page after completion of my contact form. Right now, it's just a plain, unstyled thank you, and I would like it to redirect to a page that I've desiged called contact-thank-you.html

好的,所以我想在完成我的联系表格后重定向到感谢页面。现在,它只是一个简单的、无样式的谢谢,我希望它重定向到我设计的一个名为 contact-thank-you.html 的页面

Here is my HTML form:

这是我的 HTML 表单:

<form action="form_processor.php" method="post" >
        Name:<br /><input type="text" name="name" required="required" /><br /><br />
        E-mail:<br /><input type="text" name="email" required="required" /><br /><br />
        Message:<br /><textarea name="message" required="required"></textarea><br /><br />
        <input type="submit" value="Submit">
</form>

and here is form_processor.php:

这是 form_processor.php:

    $to      = '[email protected]';
$subject = "New Message From Your Website";
$message = $_POST['message'];
$headers = 'From: ' . $_POST['name'] . ' <[email protected]>' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

echo "Thank you, you message has been sent!";

回答by Jhonathan H.

remove echo "Thank you, you message has been sent!";

消除 echo "Thank you, you message has been sent!";

because it won`t be necessary to have it since your redirecting your page then use this after all the transaction in finish to redirect

因为自从您重定向页面之后就没有必要拥有它,然后在完成所有交易后使用它来重定向

header('Location: contact-thank-you.html');
exit();

And Create a nice Thank You Templateon you contact-thank-you.html

创造一个不错的感谢模板上你contact-thank-you.html

Resources:

资源:

php.net: header()

php.net: header()

回答by John Conde

replace:

代替:

echo "Thank you, you message has been sent!";

with:

和:

header('Location: contact-thank-you.html');
exit;

reference

参考

回答by nurf

header('Location: contact-thank-you.html');

This should be the answer that you are looking for(:

这应该是您正在寻找的答案(:

You can refer to here: http://www.cyberciti.biz/faq/php-redirect/

你可以参考这里:http: //www.cyberciti.biz/faq/php-redirect/

回答by user2178229

header('Location: thank-you.php');

header('位置:thank-you.php');

or u can echo massage (ajax message on same place)

或者你可以回声按摩(在同一个地方的ajax消息)

if(@mail($address, $e_subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
     {
    echo "<p class='ajax_success'>Thanks for Contact Us.</p>";
     }
     else
     {
     echo "<p class='ajax_failure'>Sorry, Try again Later.</p>";
     }

and here ajax validation;

这里是ajax验证;

jQuery.noConflict();

jQuery(document).ready(function ($) {
    //Main Contact Form...
    jQuery("#frmcontact").validate(
    { 
        //Onblur Validation...
        onfocusout: function(element)
        {   
            $(element).valid();
        },         
        rules:
        { 
          txtname:
          {
            required: true,
            minlength: 5
          },
          txtemail:
          {
            required: true,
            email: true
          },          
         txtphone:
          {
            required: true,
            minlength: 5
          },
         txtenquiry:
          {
            required: true,
            minlength: 10
          }       
        }
    });
    //Ajax Submit...
    $('#frmcontact').submit(function () {
    if($('#txtname').is('.valid') && $('#txtemail').is('.valid') && $('#txtphone').is('.valid') && $('#txtenquiry').is('.valid')) {

        var action = $(this).attr('action');

        $("#ajax_message").slideUp(750, function () {
            $('#ajax_message').hide();

            $.post(action, {
                name: $('#txtname').val(),
                email: $('#txtemail').val(),
                phone: $('#txtphone').val(),                
                comment: $('#txtenquiry').val()
            }, function (data) {
                document.getElementById('ajax_message').innerHTML = data;
                $('#ajax_message').slideDown('slow');
                if (data.match('success') != null) $('#frmcontact').slideUp('slow');
            });
        });
      }
      return false;     
    });

and lucks very good

回答by Pir Fahim Shah

If you want to redirect from html page to another page like php page then just write this code it will work for you

如果你想从 html 页面重定向到另一个页面,比如 php 页面,那么只需编写这段代码,它就会为你工作

<?php  
  header( 'Location: http://www.yoursite.com/new_page.html' ) ; 
   //or 
  header( 'Location: nextpage.php' ) ; 
 ?>