나는 PHP에 매우 익숙하다. 그래서 필자는 필자의 연락 양식에 필수 필드를 추가하는 데 도움이 필요하다. 뷰어에게 필수 입력란에 무엇인가를 입력하라는 좋은 "오류"메시지를 표시하고 싶습니다. 여기 연락처 양식에 필수 양식 필드를 추가해야하지만 어떻게해야합니까?
내 PHP 스크립트입니다 :<?php
if(isset($_POST['submit'])){
$to = "[email protected]";
$headers = "From: " . $_POST['email'];
$subject = "Ben, you have been contacted...";
$body = "Name: " . $_POST['name'] . "\nEmail: " . $_POST['email'] . "\nWebsite: " . $_POST['web'] . "\n" . "\nFavorite Piece of work: " . $_POST['favwork'] . "\n" . "\nMessage: " . $_POST['message'];
if(mail($to, $subject, $body, $headers)){
echo("<p class=contactformsent>".$_POST['name'].", your information was received. For your records an email has also been sent to you!</p>");
}
else{
echo("<p class=contactformnotsent>".$_POST['name'].", Message delivery failed...</p>");
}
}
if(isset($_POST['submit'])){
$to = $_POST['email'];
$headers = "From: [email protected]" ;
$subject = "You contacted benlevywebdesign";
$body = $_POST['name'].", Thank you for taking a look at my portfolio and contacting me. I have received your contact information/message and I will get back to you as soon as I can!" . "\n" . "\nFor your records I have:" . "\nEmail: " . $_POST['email'] . "\nWebsite: " . $_POST['web'] . "\n" . "\nFavorite Piece of work: " . $_POST['favwork'] . "\n" . "\nMessage: " . $_POST['message'];
if(mail($to, $subject, $body, $headers)){
}
}
?>
여기에 HTML 코드 : 다음
<?php include("contactform.php"); ?>
<form id="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<fieldset>
<p class="form">Name*
<input type="text" name="name" id="name" size="30"/>
</p>
<p class="form">Email*
<input type="text" name="email" id="email" size="30" />
</p>...(the rest of the form html code here)
마지막 라인 :
<p class="submit"><button name="submit" type="submit">Send</button></p>
</form>
: 당신이 의견을 제출하면 페이지가 양식으로 돌아가려면
또한, 양식 URL은과 같이 양식에 대상 태그가 있는지 확인? –
그게 좋은 지적이야! 시청자가 제출을 클릭하면 데이터를 보내기 전에! – benlevywebdesign
클라이언트 측에서이 작업을 수행 하시겠습니까? –