清除php表单以发送另一封电子邮件

清除php表单以发送另一封电子邮件,php,forms,Php,Forms,我不确定实现这一目标的最佳方式是什么。如果用户想要发送另一个文本,我试图在PHP表单上设置输入按钮来清除表单。此时,我添加了一个event onClick=“history.go(-1);return(true);”但表单仍然显示为已填充。是否通过向按钮添加事件来实现此目的 echo "<div id='success_page_apps'>"; echo "<h1>Email Sent Successfully.</h1>"; ec

我不确定实现这一目标的最佳方式是什么。如果用户想要发送另一个文本,我试图在PHP表单上设置输入按钮来清除表单。此时,我添加了一个event onClick=“history.go(-1);return(true);”但表单仍然显示为已填充。是否通过向按钮添加事件来实现此目的

    echo "<div id='success_page_apps'>"; 
    echo "<h1>Email Sent Successfully.</h1>";
    echo "<p>Thank you, your message has been submitted to us.</p>";
    echo "</div>";
    echo "<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">";
echo”“;
回显“电子邮件已成功发送。”;
echo“谢谢,您的邮件已提交给我们。

”; 回声“; 回声“;
或者我应该更改代码其余部分的某些内容:

    $error    = '';
    $email    = ''; 
    $comments = ''; 


    if(isset($_POST['contactus'])) {

    $email    = $_POST['email'];
    $comments = $_POST['comments'];
    $app =  $_SERVER["REQUEST_URI"];;

        if(trim($comments) == '') {
        $error = '<div class="error_message">Attention! Please enter your message.</div>';
    } else if(trim($email) == '') {
        $error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
    } else if(!isEmail($email)) {
        $error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
    }

    if($error == '') {

        if(get_magic_quotes_gpc()) {
            $comments = stripslashes($comments);
        }

$address = "email@myemail.com";
$e_subject = 'You\'ve been contacted from an app web page ' . $name . '.';
$e_body = "You have been contacted using the app comments box on the above app web page, their additional message is as follows.\r\n\n";

$e_content = "\"$comments\"\r\n\n";

         $e_reply = "$name $email";

     $msg = $e_body . $e_content . $e_reply;

     mail($address, $e_subject, $msg, $app, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");

    echo "<div id='success_page_apps'>"; 
    echo "<h1>Email Sent Successfully.</h1>";
    echo "<p>Thank you, your message has been submitted to us.</p>";
    echo "</div>";
    echo '<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">';
    }

}

  if(!isset($_POST['contactus']) || $error != '') // Do not edit.
     {
?>
        <?php echo $error; ?>

        <fieldset id="contact_apps">
        <br />
        <form  method="post" action="#ContactForm">
        <label for="email" accesskey="E"><span class="required"></span> Email</label>

        <input name="email" type="text" id="email" size="33" value="<?php echo$email;?>" />

        <textarea name="comments" cols="50" rows="15"  id="comments"><?php echo$comments;?></textarea>
        <input name="contactus" type="submit" class="send" id="contactus" value="Submit">

        </form>

        </fieldset>



<?php } 
$error='';
$email='';
$comments='';
如果(isset($_POST['contactus'])){
$email=$_POST['email'];
$comments=$_POST['comments'];
$app=$\u服务器[“请求URI”];;
如果(修剪($注释)=''){
$error='注意!请输入您的消息';
}否则如果(修剪($email)=''){
$error='注意!请输入有效的电子邮件地址';
}如果(!isEmail($email)){
$error='注意!您输入的电子邮件地址无效,请重试。';
}
如果($error=''){
如果(获取\u魔术\u引号\u gpc()){
$comments=stripslashes($comments);
}
$address=”email@myemail.com";
$e_subject='已通过应用程序网页与您联系。$name';
$e_body=“已使用上述应用程序网页上的应用程序评论框与您联系,他们的附加消息如下。\r\n\n”;
$e\U content=“\”$comments\“\r\n\n”;
$e_reply=“$name$email”;
$msg=$e_body.$e_content.$e_reply;
邮件($address,$e_subject,$msg,$app,“发件人:$email\r\n收件人:$email\r\n返回路径:$email\r\n”);
回声“;
回显“电子邮件已成功发送。”;
echo“谢谢,您的邮件已提交给我们。

”; 回声“; 回声'; } } 如果(!isset($_POST['contactus'])| |$error!=''),请不要编辑。 { ?>
电子邮件
您可以使用:输入选择器来实现这一点

$(":input").val('');

这条语句将清除表单字段中的所有值。

您应该始终使用标题(“位置:…”)将用户重定向到新页面;
否则,post值将保留在内存中,页面刷新将重新发送它们。

javascript/jquery最适合这样做。需要帮助吗?为什么不直接链接回表单?还可以发送标题('location:page.php'))或者您也可以发送带有meta的标题,该标题将在您设置的时间间隔后刷新和重定向…花一点时间阅读。伪选择器选择
输入以及其他类型的输入。
:select
选择器在jQuery中根本不存在,假设您使用jQuery c进行了回答ode(问题和答案均未具体说明)。谢谢你回答我的问题。很抱歉,我对php不太熟悉,我不知道如何在我的表单上放置这段jquery。你能说得更具体一点吗。它是否会在echo之后立即包装在echo标记上?…你知道如何做吗。问题是,此表单将添加到许多每个页面都有不同的url。因此我尝试将按钮链接到页面中的特定锚定标记并清除表单。类似onClick=“location.href=this#ContactForm”的功能可能会起作用,但我不知道如何正确操作。谢谢。
$(":input").val('');