1

这里的第一个问题,所以提前谢谢!

我试图纠正的提交表单在集成验证脚本后停止工作。尽管从未发送过邮件,但它似乎可以工作。

HTML:

                <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
                <script type="text/javascript" src="js/jquery.validate.min.js"></script>

<script type="text/javascript">
/**
  * Basic jQuery Validation Form Demo Code
  * Copyright Sam Deering 2012
  * Licence: http://www.jquery4u.com/license/
  */
(function($,W,D)
{
    var JQUERY4U = {};

    JQUERY4U.UTIL =
    {
        setupFormValidation: function()
        {
            //form validation rules
            $("#contactform").validate({
                rules: {
                    firstname: "required",
                    lastname: "required",
                    email: {
                        required: true,
                        email: true
                    },
                    phone: "required",
                    comment: "required",
               },
                messages: {
                    firstname: "Please enter your firstname",
                    lastname: "Please enter your lastname",
                    email: "Please enter a valid email address",
                    phone: "Please enter a valid email phone number",
                    comment: "Please enter your reason for inquiry"
                },
                submitHandler: function(form) {
                    form.submit();
                }
            });
        }
    }

    //when the dom has loaded setup form validation rules
    $(D).ready(function($) {
        JQUERY4U.UTIL.setupFormValidation();
    });

})(jQuery, window, document);
</script>

表格:

<form action="send_form_email.php" method="post" id="contactform">

    <div id="form-content">
        <fieldset>

            <div class="fieldgroup">
                <label for="firstname">First Name*</label>
                <input type="text" name="firstname">
            </div>

            <div class="fieldgroup">
                <label for="lastname">Last Name*</label>
                <input type="text" name="lastname">
            </div>

            <div class="fieldgroup">
                <label for="email">Email*</label>
                <input type="text" name="email">
            </div>

            <div class="fieldgroup">
                <label for="phone">Phone*</label>
                <input type="text" name="phone">
            </div>

            <div class="fieldgroup">
                <label for="comment">Reason for Inquiry*</label>
                <textarea name="comment"></textarea>
            </div>

            <div class="fieldgroup">
                <input type="submit" value="Sumbit">
            </div>

        </fieldset>
    </div>
</form>

send_form_email.php:

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

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "donliggett@gmail.com";
    $email_subject = "Web Submission";

    $first_name = $_POST['firstname']; // required
    $last_name = $_POST['lastname']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $reason = $_POST['comment']; // required

    $email_message = "Form details below.\n\n";

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

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Reason for Inquiry: ".clean_string($reason)."\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 -->

谢谢大家,StackOverflow 的超级粉丝!

4

2 回答 2

0

它与 jQuery 验证无关,您只是}在末尾忘记了 aif(isset($_POST['email'])) {

?>添加前}

于 2012-08-18T00:35:59.053 回答
0

在你的最后一个之前?> 再放一个 } ;)

于 2012-08-18T00:45:54.443 回答