成功发送邮件后,如何清除/重置联系表单?

时间:2013-06-07 12:55:57

标签: php ajax forms reset clear

我收到了这封mail.php。即使成功发送电子邮件后,我的联系表单与用户提交的数据保持一致,aajaxalert表示感谢您发送的信息,但如果愚蠢的用户错过了该消息,该消息只会停留几秒钟,然后他可能会再次点击“发送”消息。如何重置整个表单?

<?php
    header('Content-Type: text/html; charset=utf-8');
    function sendFeedback($feedback_email, $feedback_msg,
            $feedback_name  , $feedback_subject)
     {
        /* EDIT THIS */
        $admin_email = "mail@website.com";
        if ($feedback_subject == "Subject" || empty($feedback_subject) ) {
            $subj = "Email from website.com.au";
        } else {
            $subj = $feedback_subject;
        }
        /* //EDIT THIS */

        $message = "
        <html>
        <head>
          <title>Email from your site</title>
        </head>
        <body>
            <p><a href='mailto:".$feedback_email."'>".$feedback_name."</a>
                       send this message:</p>
            <p>".$feedback_msg."</p>
            <p>".$subject."</p>
        </body>
        </html>
        ";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

        if (($feedback_name!=="Name" &&
             $feedback_email!=="Email" &&
             !empty($feedback_email
           ) && (
                  !empty($feedback_msg) && 
                  !empty($feedback_name))
              {
            if($feedback_email == "mail_error")
            {
              echo "<span class='ajaxok'>$feedback_name , You entered an
                            Invalid email address.</span>";
            } else {            
                mail($admin_email, $subj, $message, $headers);
                echo "<span class='ajaxok'>Thank You! $feedback_name,
                                  Your message has been sent.</span>";  
                }
        } else {
            echo "<span class='ajaxalert'>Hi $feedback_name you forgot to type
                    the  message. </span>";     
        }   
    }

    sendFeedback($_POST['email'], 
      $_POST['message'], $_POST['name'], $_POST['subject']);
    ?>

2 个答案:

答案 0 :(得分:0)

从ajax页面获得响应后,您正在显示消息,您可以使用javascript重置或清空输入字段。

答案 1 :(得分:0)

您可以使用js .reset()功能。它将表单值重置为默认值。

var form = getElementById('form_id');
form.reset();