我是php新手!我有联系表格。我需要在提交表格后清除所有字段。提交表单时,textarea不会通过表单清除。这是代码。请告诉我需要更改代码的地方。请帮我解决如何清除textarea。
<?php
if (isset($_POST['submit'])) {
$error = "";
if (!empty($_POST['name'])) {
$name = $_POST['name'];
} else {
$error .= "You didn't type in your name. <br />";
}
if (!empty($_POST['email'])) {
$email = $_POST['email'];
if (!preg_match("/^[_a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){
$error .= "The e-mail address you entered is not valid. <br/>";
}
} else {
$error .= "You didn't type in an e-mail address. <br />";
}
if (!empty($_POST['message'])) {
$message = $_POST['message'];
} else {
$error .= "You didn't type in a message. <br />";
}
if(($_POST['code']) == $_SESSION['code']) {
$code = $_POST['code'];
} else {
$error .= "The captcha code you entered does not match. Please try again. <br />";
}
if (empty($error)) {
$from = 'From: ' . $name . ' <' . $email . '>';
$to = "abc@gmail.com";
$subject = " contact form message";
$content = $name . " has sent you a message: \n
Email: $email \n
Message: $message " ;
$success = "<b>Thank you! Your message has been sent!</b>";
mail($to,$subject,$content,$from);
}
}
?>
<div id="contactForm">
<?php
if (!empty($error)) {
echo '<p class="error"><strong>Your message was NOT sent<br/> The following error(s) returned:</strong><br/>' . $error . '</p>';
} elseif (!empty($success)) {
echo $success;
}
?>
<form action="contact.php" method="post" style="margin-top:20px;">
<input type="hidden" name="subject" value="Form Submission" />
<input type="hidden" name="redirect" value="contact.php" />
<label style="font-size:14px;">Name:</label>
<input type="text" name="name" value="" style="margin-left:36px;" <?php if (isset($_POST['name'])) { echo $_POST['name']; } ?>" />
<br/>
<br/>
<label style="font-size:14px;">E-mail:</label>
<input type="text" name="email" value="" style="margin-left:30px;"<?php if (isset($_POST['email'])) { echo $_POST['email']; } ?>" />
<br/>
<br/>
<label style="float:left; margin-right:10px; font-size:14px">Comment:</label>
<textarea name="message" rows="10" cols="30" wrap="hard">
<?php if (isset($_POST['message'])) { echo $_POST['message']; } ?>
</textarea>
<br/>
<br/>
<label style="margin-left:2px;">
<img src="captcha.php" style="margin-top:10px;">
</label>
<input type="text" name="code" style="margin-left:23px;">
<br /> <br />
<input type="submit" class="submit" name="submit" value="SEND" />
</form>
答案 0 :(得分:1)
<textarea name="message" rows="10" cols="30" wrap="hard">
<?php if (isset($_POST['message'])) { echo $_POST['message']; } ?>
</textarea>
这两者之间的php行基本上说如果有一个带有参数消息的POST请求,请在那里写下该消息。
用人的话说,如果提交了表单,那么就会出现一条消息。
如果您不希望在调用提交时出现消息,则只需删除该php行。否则,请更新您的答案并尝试提供更多详细信息
答案 1 :(得分:0)
删除您使用以前的数据明确填充的代码。
<?php if (isset($_POST['message'])) { echo $_POST['message']; } ?>