2012-07-30 100 views
-1

我有一個基本的表單,我試圖重定向到與提交索引頁面不同的頁面。當我把它放在上面無法重定向提交

<!doctype html> 

header("Location: http://www.mysite.com/thanks.php"); 

工作但這不會工作在IE和我收到HTML5驗證錯誤:我只能得到這一點。

這裏是我的代碼: 在頁面的頂部:

<?php 
    include("functions/contactfunctions.php"); 



    ?> 

進一步下跌:

<?php 
    if($_POST['submitted'] == "contactus") 
    { 
    $firstname = $_POST['firstname']; 
    $lastname = $_POST['lastname']; 

    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $location = $_POST['location']; 
      if(!$firstname) 
    $error = "Please enter your first name."; 
    else 
    if(!$lastname) 
    $error = "Please enter your last name."; 
    else 
    if(!$email) 
    $error = "Please enter a valid email."; 
    else 
    if(!$message) 
    $error = "Please enter your message."; 
    else 
    if(!$location) 
    $error = "Please tell us where you're from."; 


    } 
    ?> 

    <?php 
     if($_POST['submitted']) 
     { 
     ContactMessage($firstname, $lastname, $email, $message, $location); 
     header("Location:http://www.mywebsite.com/thanks.php"); 
     exit; 
    } 

?> 

這裏是接觸的functions.php:

<?php 
include_once("databasefunctions.php"); 

$contactsdbtable = "contacts"; 

function GetHeaders() 
{ 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    // Additional headers 
    $headers .= "To: {$firstname} <{$email}>" . "\r\n"; 
    $headers .= 'From: My Site <[email protected]>' . "\r\n"; 
    return $headers; 
} 
function ContactMessage($firstname, $lastname, $email, $message, $location) 
{ 
global $contactsdbtable; 
openDatabase(); 
$firstname = mysql_real_escape_string($firstname); 
$lastname = mysql_real_escape_string($lastname); 
$email = mysql_real_escape_string($email); 
$message = mysql_real_escape_string($message); 
$location = mysql_real_escape_string($location); 

$result = QuickQuery("INSERT INTO {$contactsdbtable}(firstname, lastname, email,   message, location) 
         VALUES('{$firstname}', '{$lastname}', '{$email}', '{$message}', '{$location}')"); 

if($result) 
    { 
    $headers = GetHeaders(); 
    $message = "\"Thank you for contacting us blah blah. We will be  answering your website inquiry post haste.\"<br /> 
    <br /> 
    <br /> 
    Best Regards,<br /> 
    <br /> 
    Us 
    "; 
    mail($email, "RE: Website Inquiry", $message, $headers); 
    mail("[email protected]", "Website Inquiry", "{$firstname}, {$email}, has sent a web design inquiry", $headers); 

    } 
    } 


?> 

我有還嘗試在索引頁面上添加 並聯系fun ctions.php無濟於事。提交後,我將重定向回index.php,這是表單上的操作。

在此先感謝您的幫助!

回答

-1

If header();沒有重定向頁面,那意味着表單沒有按照提交的方式提交。 而不是檢查$ _POST ['已提交']我建議您檢查表單中的所有輸入。

if($_POST['email']&&$_POST['message']/* And so on... */){ 
    echo "echo something here so you know it ACTUALLY HAS been submitted."; 
} 

提示:使用header();確保你使用ob_start();和ob_flush();像這樣:

//Start of script 
ob_start(); 

//Now header(); will work efficiently here inside your functions... 

//End of script 
ob_flush(); 
+0

我添加了這個 - 結合去除空白似乎現在工作。謝謝 – user1505573 2012-07-30 02:59:07

2

您在開幕前有空位<?php。在發送標題之前,您不能有任何內容,並且包含空格。

+0

對不起,不確定你的空間是什麼意思?空間從什麼到什麼?和頂部<?php在哪個頁面上,索引或聯繫人功能? – user1505573 2012-07-30 02:14:16

+0

@ user1505573:在這兩個頁面上; '<?php'之前的兩個空格。帶他們出去。 – Ryan 2012-07-30 02:17:03

+0

哪個<?php有很多 - 我已經在這裏縮進它們,所以代碼會顯示出來,但是兩頁上的頂部<?php並沒有在實際代碼中縮進 – user1505573 2012-07-30 02:38:57

0

<?php 

即使空格是發送到導航信息刪除空格和換行,使頭了不是。

編輯:已答覆的答案。