안녕하세요 -이 주소의 tuto를 기반으로 한 내 사이트의 연락처 양식을 구현했습니다. http://designwoop.com/2012/07/tutorial-coding-a-jquery-popup-modal-contact-form/ 괜찮습니다. 유일한 문제는 양식에 "이름"필드를 추가하려는 것입니다. 수정 후 양식의연락처 양식 코드 사용자 정의
<input id="name" class="txt" type="name" name="name" placeholder="name"/><br />
코드 : 나는 또한 메일 보내기 PHP 파일이 추가
<form id="contact" action="#" method="post" name="contact">
<label for="name">Your Name</label>
<input id="name" class="txt" type="name" name="name" placeholder="name"/><br />
<label for="email">Your E-mail</label>
<input id="email" class="txt" type="email" name="email" placeholder="e-mail address"/>
<br />
<textarea id="msg" class="txtarea" name="msg" placeholder="Type your message here..."></textarea>
<button id="send">Send E-mail</button>
</form>
그래서 나는 형태의 HTML 코드에 코드 줄을 추가 :
$msg .= "<p><strong>From:</strong> ".$username."</p>\r\n";
메일 보내기 PHP 파일의
전체 코드 :
?php
$sendto = "[email protected]";
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
$subject = "New Message frm";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New message</h2>\r\n";
$msg .= "<p><strong>From:</strong> ".$username."</p>\r\n";
$msg .= "<p><strong>E-mail:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(@mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>
마지막 부분 : 연락처 양식의 자바 스크립트 코드. 이것은 제가 추가 한 새로운 필드 "name"에 대한 참조를 추가해야 할 필요가있는 곳입니다. 하지만 어디서? (또한 해당 필드를 필수로 설정). 귀하의 도움을 많이 주시면 감사하겠습니다. 많은 감사
// JavaScript Document
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>sending...</em>");
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Success! Your message has been sent, thank you.</strong></p>");
setTimeout("$.fancybox.close()", 1000);
});
}
}
});
}
});
});
같은 방법인가요? –
이 부분이 무엇인지 확실하지는 않지만 ... – Greg
메시지에 액세스하는' "click"'handler 함수를보십시오? 길이에 따라 유효성을 검사합니다. 이름에 대해서도 똑같은 일을 할 수 있습니다. 따라서'msglen'이 나타나면 이름과 비슷한 것을하고 싶을 것입니다. (적어도 그걸하는 한 가지 방법이고, 나중에 모델을 만들 수 있습니다.) –