最近,我一直在处理大量的表单确认。我一直在考虑如何处理这些问题的最佳方法。许多表单将用户重定向到显示感谢/确认消息的单独页面
我想在同一页面中显示mgs。我试过下面的代码,但我没有在同一页面上获得成功。它重定向到contriler.php页面
javascript文件
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#Button1").click(function(event){
$(".message").show();
$(".message").fadeOut(2500);
});
});
</script>
html文件
<div class="w-form">
<form method="POST" name="contactform" action="contact-form-handler.php" class="myform form-tablet" id="email-form" data-name="Email Form">
<select class="w-select form-select-field" id="Selection" name="Selection" required="required" data-name="Selection">
<option value="start project">Start Project</option>
<option value="work with us">Work with us</option>
<option value="just say yello">Just say hello</option>
</select>
<label class="labelfield" for="Name-3">*your Name:</label>
<input class="w-input textfield" id="Name-3" type="text" name="Name" data-name="Name" required="required">
<label class="labelfield" for="Email-3">*Your e-mail address</label>
<input class="w-input textfield" id="Email-3" type="email" name="Email" data-name="Email" required="required">
<label class="labelfield" for="Web">Your Website</label>
<input class="w-input textfield" id="Web" type="text" name="Web" data-name="Web">
<label class="labelfield" for="Message">Your Message to Us</label>
<textarea class="w-input textfield comment" id="Message" name="Message" data-name="Message"></textarea>
<input id="Button1" class="w-button submit-button" type="submit" value="Submit" data-wait="Please wait...">
</form>
<div class="message">Your update was successful.</div>
controler.php file
<?php
$errors = '';
$myemail = 'omprakash.k@fuegosys.com ';//<-----Put Your email address here.
$Selection=($_POST['Selection']);
$name=($_POST['Name']);
$email_address=($_POST['Email']);
$Web=($_POST['Web']);
$message=($_POST['Web']);
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
"$myemail /n $Selection /n $name /n $email_address/n $Web/n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: index.html#contact');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
我的问题是它没有使用sucess mgs重新登录主页
答案 0 :(得分:1)
$show_message= FALSE; // at the top of page
$message = "";
if($show_message= TRUE){
echo $message;
}
if(isset($_POST['sub'])){
//Php code goes here
$show_message = TRUE;
}
<input type ="submit" name="sub" />