Blame view
resources/js/contact/feedback.js
2.07 KB
e77200db5 Initial commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// eslint-disable-next-line import/prefer-default-export export function initFeedbackForm() { $(document).ready(function () { $('#submit').removeAttr('disabled'); $('#submit').click(function () { $('.error').hide(); $('.error ul').empty(); var hasError = false; var nameVal = $('#contactName').val(); if (nameVal == '') { $('.error ul').append('<li>Please give us your name</li>'); hasError = true; } var emailVal = $('#contactEmail').val(); var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if (emailVal == '') { $('.error ul').append('<li>Please give us your email</li>'); hasError = true; } if (!emailReg.test(emailVal)) { $('.error ul').append('<li>Please input a valid email</li>'); hasError = true; } var msgVal = $('#message').val(); if (msgVal == '') { $('.error ul').append('<li>Please enter your message</li>'); hasError = true; } var companyVal = $('#company').val(); if (hasError) { $('.error').show(); } else { $(this).attr('disabled', 'true'); $(this).attr('value', 'Sending...'); $.post('/feedback/send-mail', { contactName: nameVal, company: companyVal, contactEmail: emailVal, message: msgVal }, function (response) { $('#feedbackForm').after('<p class="success">Thank you. Your email to FootyRoom has been sent</p>'); $('#submit').attr('value', 'Sent'); }) .fail(function (response) { $('#feedbackForm').after('<p class="error">Whoops, looks like something went wrong. Try again later or report this to us.</p>'); $('#submit').attr('value', 'Sent'); }); } return false; }); }); } |