繁体   English   中英

提交后如何获得成功信息

[英]How to get success message after submit

最近,我一直在处理大量表单确认。 我一直在思考如何解决这些问题的最佳方法。 许多表单将用户重定向到显示感谢/确认消息的单独页面

我想在同一页面上显示毫克。 我已经尝试过下面的代码,但是我在同一页面上没有成功。 它重定向到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>

我的问题是它没有通过成功mgs重新转至主页

 $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" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM