first commit 2
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 파일명: contact-form-handler.js
|
||||
* 설명: 홈페이지 메인의 상담 신청 폼을 처리하는 스크립트
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
const formMessages = document.getElementById('form-messages');
|
||||
const submitButton = document.getElementById('contact-submit-btn');
|
||||
|
||||
if (contactForm && formMessages && submitButton) {
|
||||
contactForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault(); // 기본 폼 전송을 막습니다.
|
||||
|
||||
const originalButtonText = submitButton.textContent;
|
||||
submitButton.disabled = true;
|
||||
submitButton.textContent = '전송 중...';
|
||||
formMessages.style.display = 'none';
|
||||
formMessages.className = 'form-message-area'; // CSS 클래스 초기화
|
||||
|
||||
const formData = new FormData(contactForm);
|
||||
const variables = {
|
||||
contact_subject: formData.get('contact_subject'),
|
||||
contact_name: formData.get('contact_name'),
|
||||
contact_hp: formData.get('contact_hp'),
|
||||
contact_email: formData.get('contact_email'),
|
||||
// textarea의 줄바꿈을 HTML <br> 태그로 변환하여 메일에 반영합니다.
|
||||
contact_message: formData.get('contact_message').replace(/\n/g, '<br>')
|
||||
};
|
||||
|
||||
// 💡 universalMailer 객체를 사용하여 메일 발송
|
||||
window.universalMailer.send({
|
||||
template_code: 'contact_inquiry', // 관리자에서 생성할 템플릿 코드
|
||||
to_email : variables.contact_email,
|
||||
// [추가] 참조 이메일 설정
|
||||
// 'ADMIN_EMAIL' 키워드를 사용하면 서버(ajax_universal_send.php)에서
|
||||
// 실제 관리자 이메일 주소(config.php의 cf_admin_email)로 자동 치환합니다.
|
||||
// 이렇게 하면 클라이언트 코드에 이메일 주소를 노출하지 않고도 관리자에게 발송할 수 있습니다.
|
||||
cc_email: ['ADMIN_EMAIL'],
|
||||
variables: variables,
|
||||
onSuccess: function(response) {
|
||||
alert(response.message || '상담 신청이 성공적으로 접수되었습니다. 빠른 시일 내에 연락드리겠습니다.');
|
||||
contactForm.reset(); // 폼 초기화
|
||||
// formMessages.textContent = response.message || '상담 신청이 성공적으로 접수되었습니다. 빠른 시일 내에 연락드리겠습니다.';
|
||||
// formMessages.classList.add('success');
|
||||
// formMessages.style.display = 'block';
|
||||
contactForm.reset();
|
||||
// 성공 시 팝업 닫기
|
||||
const contactModal = document.getElementById('contact-modal');
|
||||
if (contactModal) {
|
||||
// 모달의 닫기 버튼을 클릭하는 방식으로 닫습니다.
|
||||
const closeButton = contactModal.querySelector('.modal-close');
|
||||
if (closeButton) closeButton.click();
|
||||
}
|
||||
},
|
||||
onError: function(errorMessage) {
|
||||
formMessages.textContent = errorMessage || '오류가 발생했습니다. 잠시 후 다시 시도해주세요.';
|
||||
formMessages.classList.add('error');
|
||||
formMessages.style.display = 'block';
|
||||
},
|
||||
onComplete: function() {
|
||||
submitButton.disabled = false;
|
||||
submitButton.textContent = originalButtonText;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user