소스 검색

Solved contact form

master
Nikola Ignjatovic 5 년 전
부모
커밋
933d32a00d
2개의 변경된 파일63개의 추가작업 그리고 61개의 파일을 삭제
  1. 3
    3
      index.html
  2. 60
    58
      scripts/custom.js

+ 3
- 3
index.html 파일 보기

<div class="one_half contact-form"> <div class="one_half contact-form">
<h3>CONTACT FORM</h3> <h3>CONTACT FORM</h3>
<h5>Do you have any questions? Send us a message</h5> <h5>Do you have any questions? Send us a message</h5>
<!-- <div class="log"></div> -->
<form id="contact-form" method="POST" action="https://formspree.io/f/xbjpojln" style="display:block!important">
<div class="log"></div>
<form id="contact-form" action="https://formspree.io/f/xbjpojln" method="POST">
<input id="name-txt" class="input-txt" name="name" type="text" placeholder="Write your name here..." required> <input id="name-txt" class="input-txt" name="name" type="text" placeholder="Write your name here..." required>
<input id="email-txt" class="input-txt" name="email" type="email" placeholder="Write your email here..." required> <input id="email-txt" class="input-txt" name="email" type="email" placeholder="Write your email here..." required>
<input id="subject-txt" class="input-txt" name="subject" type="text" placeholder="Write your subject here..." required> <input id="subject-txt" class="input-txt" name="subject" type="text" placeholder="Write your subject here..." required>
}); });
}); });
$('#contact-form #submit').on('click',function(){
$('#contact-form #submit').on('submit',function(){
setTimeout(function(){ $('.form-status-message form').show(); }, 1000); setTimeout(function(){ $('.form-status-message form').show(); }, 1000);
}); });
}); });

+ 60
- 58
scripts/custom.js 파일 보기

var button = $("#contact-form #submit"); var button = $("#contact-form #submit");
var status = $(".log"); var status = $(".log");


function success(){
function success(data){
//form.reset(); //form.reset();
form.css('display', 'block!important');
//form.css('display', 'block!important');
//button.style = "display: none "; //button.style = "display: none ";
status.addClass("successfully").text("Thanks!");
form.append(xhr.response);
} }


function error() { function error() {
status.addClass("error").text("Oops! There was a problem.");
//status.addClass("error").text("Oops! There was a problem.");
form.append(xhr.response);
} }


button.on("click", function(ev) {
button.on("submit", function(ev) {
//ev.preventDefault(); //ev.preventDefault();
//button.style = "display: none "; //button.style = "display: none ";
var data = new FormData(form); var data = new FormData(form);
if (xhr.readyState !== XMLHttpRequest.DONE) return; if (xhr.readyState !== XMLHttpRequest.DONE) return;
if (xhr.status === 200) { if (xhr.status === 200) {
success(); success();
} else { } else {
error(); error();
} }
return pattern.test(emailAddress); return pattern.test(emailAddress);
} }


$('.contact-form form').submit(function() {
// $('.contact-form form').submit(function() {
var hasError = false;
// var hasError = false;
var comment = $('#message-txt').val();
if ($.trim(comment) == '') {
$('#message-txt').addClass('error');
$('#message-txt').focus();
hasError = true;
}
else {
$('#message-txt').removeClass('error');
}
var subject = $('#subject-txt').val();
if ($.trim(subject) == '') {
$('#subject-txt').addClass('error');
$('#subject-txt').focus();
hasError = true;
}
else {
$('#subject-txt').removeClass('error');
}
// var comment = $('#message-txt').val();
// if ($.trim(comment) == '') {
// $('#message-txt').addClass('error');
// $('#message-txt').focus();
// hasError = true;
// }
// else {
// $('#message-txt').removeClass('error');
// }
// var subject = $('#subject-txt').val();
// if ($.trim(subject) == '') {
// $('#subject-txt').addClass('error');
// $('#subject-txt').focus();
// hasError = true;
// }
// else {
// $('#subject-txt').removeClass('error');
// }
var emailVal = $('#email-txt').val();
if ($.trim(emailVal) == '' || !isValidEmailAddress(emailVal)) {
$('#email-txt').addClass('error');
$('#email-txt').focus();
hasError = true;
}
else {
$('#email-txt').removeClass('error');
}
// var emailVal = $('#email-txt').val();
// if ($.trim(emailVal) == '' || !isValidEmailAddress(emailVal)) {
// $('#email-txt').addClass('error');
// $('#email-txt').focus();
// hasError = true;
// }
// else {
// $('#email-txt').removeClass('error');
// }
var name = $('#name-txt').val();
if ($.trim(name) == '') {
$('#name-txt').addClass('error');
$('#name-txt').focus();
hasError = true;
// var name = $('#name-txt').val();
// if ($.trim(name) == '') {
// $('#name-txt').addClass('error');
// $('#name-txt').focus();
// hasError = true;
}
else {
$('#name-txt').removeClass('error');
}
// }
// else {
// $('#name-txt').removeClass('error');
// }
if (!hasError) {
$('#submit').fadeOut('normal', function(){
$('.loading').css({
display: "block"
});
// if (!hasError) {
// $('#submit').fadeOut('normal', function(){
// $('.loading').css({
// display: "block"
// });
});
// });
$.post($('.contact-form form').attr('action'), $('.contact-form form').serialize(), function(data){
$('.log').html(data);
$('.loading').remove();
$('.contact-form form').slideUp('slow');
});
// // $.post($('.contact-form form').attr('action'), $('.contact-form form').serialize(), function(data){
// // $('.log').html(data);
// // $('.loading').remove();
// // $('.contact-form form').slideUp('slow');
// // });
}
// }
return false;
// return false;
});
// });





Loading…
취소
저장