隐藏联系表格并淡入谢谢你的消息

时间:2011-06-24 03:18:07

标签: php html forms

我很难将这个用于表单。我看过这篇文章Show a Thank You message after validating contact form,但我又无法让它为我的工作。

我的表单代码是

<li id="contact">
                    <form enctype="multipart/form-data" method="post" action="contact2.php" name="contactform" id="contactform">
                                                <p>Jason Bartimus | Hawaii Wedding Photographer</p>
                        <h3>What type of session are you interested in?</h3>
                        <ul>
                            <li class="msgname"><label>Full Name: </label><input type="text" name="name"></li>
                            <li><label>E-mail: </label><input type="text" name="email"></li>
                            <li class="msgname"><label>Contact Number: </label><input type="text" name="phone"></li>
                            <li><label>Event Date: </label><input type="text" name="date"></li>                             
                            <li><label>Event Type: </label><select name="event">
                                    <option>- - - - - - -</option>
                                    <option value="Engagement">Engagement</option>                      
                                    <option value="Wedding">Wedding</option>
                                </select></li>                                    
                            <li><label>Message: </label><textarea name="message" rows=4 cols=35></textarea></li>
                            <li><input class="send" type="submit" value="Send"></li>
                        </ul>
                        </form>
                        <div id="contactinfo">
                            <h3>Contact Information</h3>
                            <p></p>
                            <p class="phone">808-343-0845</p>
                            <p class="email"><a href="#">info@jasonbartimus.com</a></p>
                        </div>
                     </li>  

我的PHP代码在这里:

<?php 
$ToEmail = 'info@jasonbartimus.com'; 
$EmailSubject = 'Site contact form '; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "phone: ".$_POST["phone"]."<br>";
$MESSAGE_BODY .= "date: ".$_POST["date"]."<br>"; 
$MESSAGE_BODY .= "event: ".$_POST["event"]."<br>"; 
$MESSAGE_BODY .= "message: ".nl2br($_POST["message"])."<br>"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

我不知道如何让它发挥作用。任何帮助都会很棒!

我不知道如何让它发挥作用。任何帮助都会很棒! 试图以某种方式使用这个jquery

$(function() {
var options = {
    messages: {
        firstname: "Please enter your Name",
        lastname: "Please enter your Last Name",
        email: "Please enter a valid E-mail Address",
        comments: "Please enter your Comments"
    },
    submitHandler: function(form) {
        $(form).ajaxSubmit({
            beforeSubmit: function(arr, $form, options) {
                $('#myform').fadeOut('fast');
                $('#loader').fadeIn('slow');
                return true;
            },
            success: processRegister
        });
    }
};

//Validation
$('#contactus').validate(options);
$('#ty').hide();

});

function processRegister(responseText, status) {
    $('#loader').fadeOut(function() {
        $('#ty').fadeIn();
    });
}

1 个答案:

答案 0 :(得分:0)

查看代码时,您没有#ty

表示的元素

您可以使用当前的HTML并将其打包在<section><div> HTML标记中。像:

 <section name="form">
     --- all your form html goes here
 </section>

然后感谢你的消息:

 <section name="ty">
     --- thank you message
 </section>

使用一些jquery善良隐藏谢谢部分并仅在提交表单时显示...然后隐藏“表单”部分