首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在提交后获取成功消息

如何在提交后获取成功消息
EN

Stack Overflow用户
提问于 2014-11-07 20:51:06
回答 1查看 2.6K关注 0票数 1

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

我想在同一页中显示mgs。我已经尝试了下面的代码,但我没有成功的mgs在同一页。它将重定向到contriler.php页面

javascript文件

代码语言: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文件

代码语言:javascript
复制
<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>

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2014-11-07 21:37:55

代码语言:javascript
复制
 $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" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26801638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档