2015-06-23 81 views
-1

我有一個聯繫表(來自互聯網)結果以HTML頁面

<form name="htmlform" method="post" action="html_form_send.php"> 
<<<FORM>>>> 
<input type="submit" value="Verstuur"> 
</form> 

之後,它進入html_form_send.php

有了一些消息,當您更迭或錯誤,例如:

if(!preg_match($email_exp,$email_from)) { 
$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 

它的偉大工程,只有我想的第一個HTML頁面(./contact.html)的形式下對消息(您輸入的電子郵件地址似乎不是有效)。我該怎麼做呢?

謝謝你的時間。

+0

發送帶有額外URL參數的標頭http://php.net/manual/en/function.header.php – zod

回答

0

HTML表單在完成時不會採取任何形式的回調,但您可以嘗試的一種方法是使用GET變量重定向回contact.html,以便通知頁面您的電子郵件地址格式錯誤。

例如,在contact.php

<?php 
    if(isset($_GET['msg']) && $_GET['msg'] == "emailerror") { 
     echo "<p>The Email Address you entered does not appear to be valid.</p>"; 
    } 
?> 

和上html_form_send.php,

if(!preg_match(...)) { 
    header('location: contact.html?msg=emailerror'); 
} 
0
<form id="htmlform" name="htmlform" method="post" action="html_form_send.php"> 
<<<FORM>>>> 
</form> 
<div id="result"></div> 

在腳本

$(document).ready(function() { 

$("#htmlform").submit(function(e){ 
    e.preventDefault(); 

    $.post("html_form_send.php", function(data) { 
     var frm = $("#htmlform"); 
     var data = JSON.stringify(frm.serializeArray()); 
     $(".result").html(data); 
    });//post 

});//form 

});//ready 

參考http://api.jquery.com/jquery.post/