2010-09-26 32 views
1

我需要將表單值從一個頁面發送到另一個頁面,並從該頁面發送到第三個頁面。我需要第三頁第一頁的表單值。我該怎麼做?如何記住不同頁面上的表單值?

我有將表單值傳遞到下一頁的代碼。我怎樣才能將相同的表單值發送到第三頁?

<script type="text/javascript" src="jquery-1.2.6.min.js"></script> 

<script type="text/javascript">           
    // we will add our javascript code here   

$(document).ready(function(){ 
$("#ajax-contact-form").submit(function(){ 

var str = $(this).serialize(); 

    $.ajax({ 
    type: "POST", 
    url: "contact.php", 
    data: str, 
    success: function(msg){ 

$("#note").ajaxComplete(function(event, request, settings){ 

if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form 
{ 
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>'; 
window.location.href = "http://www.google.com"; 
$("#fields").hide(); 
} 
else 
{ 
result = msg; 
} 

$(this).html(result); 

}); 

} 

}); 

return false; 

}); 

}); 

</script> 

回答

2

可以使用GET

window.location.href = "http://yourdoamin?value= serialize text variable"; 
+0

謝謝...我如何閱讀當我使用GET第三頁中的值?任何例子會很好 – Prady 2010-09-26 13:18:53

+0

看看這個:http://stackoverflow.com/questions/1352214/serialize-unserialize-in-jquery – 2010-09-26 13:25:28

+0

我已更新後,請檢查它 – 2010-09-26 13:26:02

0

使用sessions - 這裏是一個Tutorial

+0

它只是一個html頁面..不知道我們c這裏的會話 – Prady 2010-09-26 13:19:47

+0

如果您有php發送郵件,請使用新的表單返回第3頁的值。或者讓PHP發送值到第3頁 – mplungjan 2010-09-26 13:29:39

0

您可以從表#1​​表格2#設定的值。這樣,當您提交表格#2時,值將以表格#3提供。

+0

我沒有形式在第二頁。它只是第二頁是一個PHP頁面,發送電子郵件之後,頁面1的表單值被重定向到頁面3 – Prady 2010-09-26 13:22:28

+0

然後像其他人所建議的那樣,您可以在會話中存儲值... – 2010-09-26 13:38:11

1

假設你只使用簡單的值(不通過數組),你可以做這樣的事情:

echo "<form id='second_page' method='post' action='third_page.php'>"; 
foreach ($x in $_POST) { 
    echo '<input type="hidden" name="' . htmlspecialchars($x) . '" value="' . htmlspecialchars($_POST[$x]) . '" />'; 
} 
相關問題