Created
May 4, 2017 21:06
-
-
Save ixis-kyle/c7280ea4cc7426b9d2d6b82f89caa70d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#contact-form').submit(function(e) { | |
console.log(321); | |
e.preventDefault(); | |
var bad; | |
// email regular expression to validate email | |
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; | |
// successful form fillout variable | |
// default is false - set ti false by default but if filled out correctly changes to true | |
var successfulSubmit = false; | |
var contactFirstName = $('#contactFormFName').val(); | |
var contactLastName = $('#contactFormLName').val(); | |
var contactEmail = $('#contactFormEmail').val(); | |
var contactMessage = $('#contactFormMessage').val(); | |
if (contactFirstName === '') { | |
bad = true; | |
$('#contactFormFName').css('border-color', '#f84141'); | |
$('#contactFormFName').after('<br><span class="field-error">Please enter your name</span>'); | |
$('#contact-form :submit').attr('disabled', true); | |
} | |
if (contactLastName === '') { | |
bad = true; | |
$('#contactFormLName').css('border-color', '#f84141'); | |
$('#contactFormLName').after('<br><span class="field-error">Please enter your name</span>'); | |
$('#contact-form :submit').attr('disabled', true); | |
} | |
if (emailReg.test(contactEmail) === false || contactEmail === '') { | |
bad = true; | |
$('#contactFormEmail').css('border-color', '#f84141'); | |
$('#contactFormEmail').after('<br><span class="field-error">Please enter valid email</span>'); | |
$('#contact-form :submit').attr('disabled', true); | |
} | |
if (contactMessage === '') { | |
bad = true; | |
$('#contactFormMessage').css('border-color', '#f84141'); | |
$('#contactFormMessage').after('<br><span class="field-error">Please enter your password</span>'); | |
$('#contact-form :submit').attr('disabled', true); | |
} | |
console.log(bad); | |
// referencing earlier variable | |
if (!bad) { | |
$.ajax({ | |
type: 'post', | |
url: 'https://blog.masterdynamic.com/contact-mailer.php', | |
data: { | |
'firstName': $('#contactFormFName').val(), | |
'lastName': $('#contactFormLName').val(), | |
'userEmail': $('#contactFormEmail').val(), | |
'mail': $('#contactFormCategory :selected').val(), | |
'message': $('#contactFormMessage').val() | |
} | |
}); | |
$('#contact-form :submit').attr('disabled', true); | |
$('.success').css('visibility', 'visible'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment