2013-02-18 111 views
1

我在這個論壇中嘗試了很多東西,但我無法獲得重定向工作或任何事情。我編寫它的方式,它顯示一個新頁面,並顯示一條成功消息,但用戶必須通過瀏覽器進行備份才能發現自己仍然顯示所有信息。在PHP中提交表單後顯示一個彈出消息

我需要清除盒子並顯示彈出的成功消息。我該怎麼做呢?

謝謝

這裏是我的PHP

<?php 
if(isset($_POST['email'])) { 

// EDIT THE 2 LINES BELOW AS REQUIRED 
$email_to = "[email protected]"; 
$email_subject = "Your email subject line"; 


function died($error) { 
    // your error code can go here 
    echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
    echo "These errors appear below.<br /><br />"; 
    echo $error."<br /><br />"; 
    echo "Please go back with the browser back button and fix these errors.<br /><br />"; 
    die(); 
} 

// validation expected data exists 
if(!isset($_POST['name']) || 
    !isset($_POST['phone']) || 
    !isset($_POST['email']) || 
    !isset($_POST['service']) || 
    !isset($_POST['bedrooms']) || 
    !isset($_POST['bathrooms'])){ 
    died('We are sorry, but there appears to be a problem with the form you submitted.');  
} 

$name = $_POST['name']; // required 
$phone = $_POST['phone']; // required 
$email_from = $_POST['email']; // required 
$service = $_POST['service']; // required 
$bedrooms = $_POST['bedrooms']; // not required 
$bathrooms = $_POST['bathrooms']; // not required 

$error_message = ""; 
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$name)) { 
    $error_message .= 'The name you entered does not appear to be valid.<br />'; 
    } 

    $string_exp = "/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"; 
    if(!preg_match($string_exp,$phone)) { 
    $error_message .= 'The number you entered does not appear to be valid.<br />'; 
    } 

    if(strlen($error_message) > 0) { 
     died($error_message); 
    } 
    $email_message = "The following quote has been requested. \n\n"; 

function clean_string($string) { 
    $bad = array("content-type","bcc:","to:","cc:","href"); 
    return str_replace($bad,"",$string); 
} 

$email_message .= "Name: ".clean_string($name)."\n"; 
$email_message .= "Phone: ".clean_string($phone)."\n"; 
$email_message .= "Email: ".clean_string($email_from)."\n"; 
$email_message .= "Service: ".clean_string($service)."\n"; 
$email_message .= "Bedrooms: ".clean_string($bedrooms)."\n"; 
$email_message .= "Bathrooms: ".clean_string($bathrooms)."\n"; 


// create email headers 
    $headers = 'From: '.$email_from."\r\n". 
    'Reply-To: '.$email_from."\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 
    @mail($email_to, $email_subject, $email_message, $headers); 
?> 

<!-- include your own success html here --> 

<?php 
    } 
    ?> 

,這裏是我的形式

<form action="bin/quote.php" method="post" id="search" enctype="multipart/form-data" onSubmit="alert('Thank you!')"; > 
    <table summary="Search form" cellspacing="2" cellpadding="5">      
     <tr> 
      <th style="color:#c1c2c3; font-weight:bold">REQUEST A QUOTE</th> 
     </tr>      
     <tr> 
      <td colspan="5">Name: <input style="margin-left: 55px" type="text" class="text" name="name" /></td> 
     </tr> 
     <tr> 
      <td colspan="10">Phone:<input style="margin-left: 55px" type="text" class="text" name="phone" placeholder="XXX-XXX-XXXX" /></td> 
     </tr> 
     <tr> 
      <td colspan="5">Email:<input style="margin-left: 55px" type="text" class="text" name="email" /></td> 
     </tr> 
     <tr> 
      <th>Service Required:</th> 
     <td colspan="3"> 
      <select name="service"> 
       <option value="Residential Move">Residential Move*</option> 
       <option value="Commercial Move">Commercial Move*</option> 
       <option value="Storage Unit Loading">Storage Unit Loading</option> 
       <option value="Storage Unit Unloading">Storage Unit Unloading</option> 
       <option value="Furniture Consignment">Furniture Consignment</option> 
       <option value="Assembly/Removal">Assembly/Removal</option> 
       <option value="Landscaping">Landscaping</option> 
       <option value="Cleanout">Cleanout</option> 
       <option value="General Help">General Help</option> 
      </select> 
     </td> 
     </tr> 
     <tr> 
     <td style="color:#c1c2c3"><b>*If a move...</b></td> 
     </tr> 
     <tr> 
     <th>Bedrooms:</th> 
     <td> 
      <select name="bedrooms"> 
       <option value="1">1</option> 
       <option value="2">2</option> 
       <option value="3">3</option> 
       <option value="4">4</option> 
       <option value="5">5+</option> 
      </select> 
     </td>       
     <th>Bathrooms:</th> 
     <td> 
      <select name="bathrooms"> 
       <option value="1">1</option> 
       <option value="2">2</option> 
       <option value="3">3</option> 
       <option value="4">4</option> 
       <option value="5">5+</option> 
      </select> 
     </td> 
     </tr> 
     <tr>        
     <td><a onclick="document.getElementById('search').submit()"><button type="submit" value="SEND" class="more">Send</button></a></td> 
     </tr> 
    </table> 
</form> 

任何幫助將不勝感激

回答

1

使用重定向:

... 
@mail($email_to, $email_subject, $email_message, $headers); 
header('location: success.php'); //send them wherever you want so they don't have to use back button 
die(); 
+0

非常感謝!這很好用! – LOTUSMS 2013-02-18 18:14:37