Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交表单后如何清除文本区域_Php_Html - Fatal编程技术网

Php 提交表单后如何清除文本区域

Php 提交表单后如何清除文本区域,php,html,Php,Html,我是php新手!我有一张联系表。我需要在提交表单后清除所有字段。提交表单时,文本区域不会被表单清除。这是代码。请告诉我哪里需要更改代码。请帮助我如何清除文本区域 <?php if (isset($_POST['submit'])) { $error = ""; if (!empty($_POST['name'])) { $name = $_POST['name']; } else { $error .= "You didn't type

我是php新手!我有一张联系表。我需要在提交表单后清除所有字段。提交表单时,文本区域不会被表单清除。这是代码。请告诉我哪里需要更改代码。请帮助我如何清除文本区域

<?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>

删除用以前的数据显式填充的代码

<?php  if (isset($_POST['message'])) { echo $_POST['message']; } ?>


这两者之间的php行基本上表示,如果有带有参数消息的POST请求,请将该消息写入其中

用人类的话来说,如果表单被提交,那么就会出现一条消息


如果您不希望在调用submit时出现消息,那么只需删除该php行即可。否则,请更新您的答案并尝试提供更多详细信息

这些标签元素是无用的。它们与任何表单控件都没有关联。查看
for
属性的工作方式。
<textarea name="message" rows="10" cols="30" wrap="hard">
   <?php  if (isset($_POST['message'])) { echo $_POST['message']; } ?>
</textarea>