first commit 2
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 파일명: contact-form-handler.js
|
||||
* 설명: 홈페이지 메인의 상담 신청 폼을 처리하고 팝업을 제어하는 스크립트
|
||||
*/
|
||||
|
||||
// 💡 [핵심 수정] jQuery를 사용하여 팝업 열기/닫기 기능 구현
|
||||
$(function() {
|
||||
const $modal = $('#contact-modal');
|
||||
|
||||
// '문의' 링크 클릭 시 팝업 열기
|
||||
$('#open-contact-modal').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$modal.addClass('active');
|
||||
});
|
||||
|
||||
// 닫기 버튼 클릭 시 팝업 닫기
|
||||
$modal.on('click', '.modal-close', function(e) {
|
||||
e.preventDefault();
|
||||
$modal.removeClass('active');
|
||||
});
|
||||
|
||||
// 팝업 배경 클릭 시 닫기
|
||||
$modal.on('click', function(e) {
|
||||
if ($(e.target).is($modal)) {
|
||||
$modal.removeClass('active');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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_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) 로드 여부 확인
|
||||
if (!window.universalMailer) {
|
||||
alert('메일 발송 모듈(Agent)이 로드되지 않았습니다.\n페이지를 새로고침 하거나 관리자에게 문의하세요.');
|
||||
submitButton.disabled = false;
|
||||
submitButton.textContent = originalButtonText;
|
||||
return;
|
||||
}
|
||||
|
||||
// 💡 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(); // 폼 초기화
|
||||
// 성공 시 팝업 닫기
|
||||
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