簡體   English   中英

如何在PHP中重定向到“謝謝”頁面

[英]How can I redirect to a thank you page in PHP

好的,所以我想在完成聯系表格后重定向到“謝謝”頁面。 現在,這只是一個普通的,沒有樣式的謝謝,我希望它重定向到我指定的一個名為contact-thank-you.html的頁面。

這是我的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>

這是form_processor.php:

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

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

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

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

因為自從您重定向頁面以來就不需要它了,然后在完成所有事務后使用它來重定向

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

並在您上創建一個不錯的感謝模板 contact-thank-you.html

資源:

php.net: 標頭()

更換:

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

與:

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

參考

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

這應該是您正在尋找的答案(:

您可以在這里參考: http : //www.cyberciti.biz/faq/php-redirect/

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

或者您可以回聲按摩(在同一位置顯示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>";
     }

這里是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

如果您想從html頁面重定向到另一個頁面(例如php頁面),則只需編寫以下代碼即可使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM