2014-01-14 5 views
-1

나는 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 = "[email protected]"; 
    $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

이러한 레이블 요소는 쓸모가 없습니다. 그들은 어떤 폼 컨트롤과도 관련이 없습니다. 'for' 속성이 어떻게 작동하는지보세요. – Quentin

답변

0

명시 적으로 이전 데이터로 채우는 코드를 제거하십시오.

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

감사합니다. – user3168637

1
<textarea name="message" rows="10" cols="30" wrap="hard"> 
    <?php if (isset($_POST['message'])) { echo $_POST['message']; } ?> 
</textarea> 

그 두 사이의 PHP 라인은 기본적으로 매개 변수 메시지와 POST 요청이있는 경우, 거기 메시지를 작성 말한다.

인간의 단어로 양식을 제출하면 메시지가 나타납니다.

제출을 호출 할 때 메시지를 표시하지 않으려면 해당 PHP 행을 제거하십시오. 그렇지 않으면 대답을 업데이트하고 자세한 내용을 알려주십시오.

관련 문제