init
This commit is contained in:
92
contactform/contactform.js
Normal file
92
contactform/contactform.js
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 수지 AI·데이터 아카데미 Contact Form - lightweight AJAX submitter
|
||||
* Expects the server endpoint to respond with plain text: "OK" on success, otherwise an error message.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function byId(id) { return document.getElementById(id); }
|
||||
|
||||
function show(el, visible) {
|
||||
if (!el) return;
|
||||
el.style.display = visible ? "block" : "none";
|
||||
}
|
||||
|
||||
function setText(el, text) {
|
||||
if (!el) return;
|
||||
el.textContent = text || "";
|
||||
}
|
||||
|
||||
function validateEmail(email) {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(email || "").trim());
|
||||
}
|
||||
|
||||
function getFormMessage(form) {
|
||||
var name = (form.querySelector('input[name="name"]') || {}).value || "";
|
||||
if (name.trim().length < 2) return "이름을 입력해주세요.";
|
||||
|
||||
var email = (form.querySelector('input[name="email"]') || {}).value || "";
|
||||
if (!validateEmail(email)) return "이메일을 올바르게 입력해주세요.";
|
||||
|
||||
var subject = (form.querySelector('input[name="subject"]') || {}).value || "";
|
||||
if (subject.trim().length < 4) return "제목을 입력해주세요.";
|
||||
|
||||
var message = (form.querySelector('textarea[name="message"]') || {}).value || "";
|
||||
if (message.trim().length < 10) return "내용을 조금 더 자세히 입력해주세요(10자 이상).";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
var forms = document.querySelectorAll("form.contactForm");
|
||||
if (!forms || !forms.length) return;
|
||||
|
||||
Array.prototype.forEach.call(forms, function (form) {
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var sendmessage = byId("sendmessage");
|
||||
var errormessage = byId("errormessage");
|
||||
|
||||
show(sendmessage, false);
|
||||
show(errormessage, false);
|
||||
setText(errormessage, "");
|
||||
|
||||
var validationMsg = getFormMessage(form);
|
||||
if (validationMsg) {
|
||||
setText(errormessage, validationMsg);
|
||||
show(errormessage, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var action = form.getAttribute("action") || "contactform/contactform.php";
|
||||
|
||||
var fd = new FormData(form);
|
||||
|
||||
fetch(action, {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
credentials: "same-origin"
|
||||
})
|
||||
.then(function (res) { return res.text(); })
|
||||
.then(function (text) {
|
||||
var t = (text || "").trim();
|
||||
if (t === "OK") {
|
||||
show(sendmessage, true);
|
||||
setText(errormessage, "");
|
||||
show(errormessage, false);
|
||||
form.reset();
|
||||
} else {
|
||||
setText(errormessage, t || "메일 전송에 실패했습니다. 잠시 후 다시 시도해주세요.");
|
||||
show(errormessage, true);
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
setText(errormessage, "메일 전송 중 오류가 발생했습니다. 네트워크/서버 상태를 확인해주세요.");
|
||||
show(errormessage, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
71
contactform/contactform.php
Normal file
71
contactform/contactform.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// 수지 AI·데이터 아카데미 Contact Form mail handler
|
||||
// Returns plain text: "OK" on success, otherwise an error message.
|
||||
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
|
||||
function fail($msg) {
|
||||
http_response_code(400);
|
||||
echo $msg;
|
||||
exit;
|
||||
}
|
||||
|
||||
function post($key) {
|
||||
return isset($_POST[$key]) ? trim((string)$_POST[$key]) : '';
|
||||
}
|
||||
|
||||
$to = 'dsyoon@ncue.net';
|
||||
|
||||
$name = post('name');
|
||||
$email = post('email');
|
||||
$subject = post('subject');
|
||||
$message = post('message');
|
||||
|
||||
if (mb_strlen($name) < 2) fail('이름을 입력해주세요.');
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) fail('이메일을 올바르게 입력해주세요.');
|
||||
if (mb_strlen($subject) < 4) fail('제목을 입력해주세요.');
|
||||
if (mb_strlen($message) < 10) fail('내용을 조금 더 자세히 입력해주세요(10자 이상).');
|
||||
|
||||
// Basic sanitization
|
||||
$safe_name = str_replace(array("\r", "\n"), ' ', strip_tags($name));
|
||||
$safe_subject = str_replace(array("\r", "\n"), ' ', strip_tags($subject));
|
||||
$safe_email = filter_var($email, FILTER_SANITIZE_EMAIL);
|
||||
$safe_message = trim(strip_tags($message));
|
||||
|
||||
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
|
||||
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
|
||||
$mail_subject = '[수지 AI·데이터 아카데미 문의] ' . $safe_subject;
|
||||
$mail_body =
|
||||
"수지 AI·데이터 아카데미 문의가 도착했습니다.\n\n" .
|
||||
"이름: {$safe_name}\n" .
|
||||
"이메일: {$safe_email}\n" .
|
||||
"제목: {$safe_subject}\n" .
|
||||
"시간: {$ts}\n" .
|
||||
"IP: {$ip}\n" .
|
||||
"User-Agent: {$ua}\n\n" .
|
||||
"내용:\n" .
|
||||
"{$safe_message}\n";
|
||||
|
||||
// Many hosts reject arbitrary From. Use a neutral From and set Reply-To to the user.
|
||||
$from = 'no-reply@ncue.net';
|
||||
$headers = array();
|
||||
$headers[] = 'MIME-Version: 1.0';
|
||||
$headers[] = 'Content-Type: text/plain; charset=UTF-8';
|
||||
$headers[] = 'From: 수지 AI·데이터 아카데미 <' . $from . '>';
|
||||
$headers[] = 'Reply-To: ' . $safe_email;
|
||||
$headers[] = 'X-Mailer: PHP/' . phpversion();
|
||||
|
||||
$ok = mail($to, $mail_subject, $mail_body, implode("\r\n", $headers));
|
||||
|
||||
if ($ok) {
|
||||
echo "OK";
|
||||
exit;
|
||||
}
|
||||
|
||||
http_response_code(500);
|
||||
echo "메일 전송에 실패했습니다. 서버 메일 설정(sendmail/SMTP)을 확인해주세요.";
|
||||
exit;
|
||||
|
||||
|
||||
2
contactform/readme.txt
Normal file
2
contactform/readme.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Fully working PHP/AJAX contact form is avaialbe in the pro version.
|
||||
You can buy it from: https://bootstrapmade.com/buy/?theme=Moderna
|
||||
Reference in New Issue
Block a user