Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $('#send_message').click(function(e){
- //Stop form submission & check the validation
- e.preventDefault();
- // Variable declaration
- var error = false;
- var lname = $('#lname').val();
- var fname = $('#fname').val();
- var mname = $('#mname').val();
- var alias = $('#alias').val();
- var place = $('#place').val();
- var address = $('#address').val();
- var nationality = $('#nationality').val();
- var age = $('#age').val();
- var complexion = $('#complexion').val();
- var height = $('#height').val();
- var weight = $('#weight').val();
- var build = $('#build').val();
- var haircolor = $('#haircolor').val();
- var pecularities = $('#pecularities').val();
- var other = $('#other').val();
- var clname = $('#clname').val();
- var cfname = $('#cfname').val();
- var cmname = $('#cmname').val();
- var caddress = $('#caddress').val();
- var email = $('#email').val();
- var subject = $('#subject').val();
- var message = $('#message').val();
- // Form field validation
- if(lname.length == 0){
- var error = true;
- $('#lname_null').fadeIn(500);
- }else{
- $('#lname_null').fadeOut(500);
- }
- if(!lname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#lname_error').fadeIn(500);
- }else{
- $('#lname_error').fadeOut(500);
- }
- if(fname.length == 0){
- var error = true;
- $('#fname_null').fadeIn(500);
- }else{
- $('#fname_null').fadeOut(500);
- }
- if(!fname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#fname_error').fadeIn(500);
- }else{
- $('#fname_error').fadeOut(500);
- }
- if(mname.length == 0){
- var error = true;
- $('#mname_null').fadeIn(500);
- }else{
- $('#mname_null').fadeOut(500);
- }
- if(!mname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#mname_error').fadeIn(500);
- }else{
- $('#mname_error').fadeOut(500);
- }
- if(alias.length == 0){
- var error = true;
- $('#alias_null').fadeIn(500);
- }else{
- $('#alias_null').fadeOut(500);
- }
- if(!alias.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#alias_error').fadeIn(500);
- }else{
- $('#alias_error').fadeOut(500);
- }
- if(place.length == 0){
- var error = true;
- $('#place_null').fadeIn(500);
- }else{
- $('#place_null').fadeOut(500);
- }
- if(!place.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#place_error').fadeIn(500);
- }else{
- $('#place_error').fadeOut(500);
- }
- if(address.length == 0){
- var error = true;
- $('#address_null').fadeIn(500);
- }else{
- $('#address_null').fadeOut(500);
- }
- if(!address.match(/^[a-zA-Z0-9 #-]*$/)){
- var error = true;
- $('#address_error').fadeIn(500);
- }else{
- $('#address_error').fadeOut(500);
- }
- if(nationality.length == 0){
- var error = true;
- $('#nationality_null').fadeIn(500);
- }else{
- $('#nationality_null').fadeOut(500);
- }
- if(!nationality.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#nationality_error').fadeIn(500);
- }else{
- $('#nationality_error').fadeOut(500);
- }
- if(age.length == 0){
- var error = true;
- $('#age_null').fadeIn(500);
- }else{
- $('#age_null').fadeOut(500);
- }
- if(!age.match(/^[0-9]*$/)){
- var error = true;
- $('#age_error').fadeIn(500);
- }else{
- $('#age_error').fadeOut(500);
- }
- if(complexion.length == 0){
- var error = true;
- $('#complexion_null').fadeIn(500);
- }else{
- $('#complexion_null').fadeOut(500);
- }
- if(!complexion.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#complexion_error').fadeIn(500);
- }else{
- $('#complexion_error').fadeOut(500);
- }
- if(height.length == 0){
- var error = true;
- $('#height_null').fadeIn(500);
- }else{
- $('#height_null').fadeOut(500);
- }
- if(!height.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#height_error').fadeIn(500);
- }else{
- $('#height_error').fadeOut(500);
- }
- if(weight.length == 0){
- var error = true;
- $('#weight_null').fadeIn(500);
- }else{
- $('#weight_null').fadeOut(500);
- }
- if(!weight.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#weight_error').fadeIn(500);
- }else{
- $('#weight_error').fadeOut(500);
- }
- if(build.length == 0){
- var error = true;
- $('#build_null').fadeIn(500);
- }else{
- $('#build_null').fadeOut(500);
- }
- if(!build.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#build_error').fadeIn(500);
- }else{
- $('#build_error').fadeOut(500);
- }
- if(haircolor.length == 0){
- var error = true;
- $('#haircolor_null').fadeIn(500);
- }else{
- $('#haircolor_null').fadeOut(500);
- }
- if(!haircolor.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#haircolor_error').fadeIn(500);
- }else{
- $('#haircolor_error').fadeOut(500);
- }
- if(pecularities.length == 0){
- var error = true;
- $('#pecularities_null').fadeIn(500);
- }else{
- $('#pecularities_null').fadeOut(500);
- }
- if(!pecularities.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#pecularities_error').fadeIn(500);
- }else{
- $('#pecularities_error').fadeOut(500);
- }
- if(other.length == 0){
- var error = true;
- $('#other_null').fadeIn(500);
- }else{
- $('#other_null').fadeOut(500);
- }
- if(!other.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#other_error').fadeIn(500);
- }else{
- $('#other_error').fadeOut(500);
- }
- if(clname.length == 0){
- var error = true;
- $('#clname_null').fadeIn(500);
- }else{
- $('#clname_null').fadeOut(500);
- }
- if(!clname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#clname_error').fadeIn(500);
- }else{
- $('#clname_error').fadeOut(500);
- }
- if(cfname.length == 0){
- var error = true;
- $('#cfname_null').fadeIn(500);
- }else{
- $('#cfname_null').fadeOut(500);
- }
- if(!cfname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#cfname_error').fadeIn(500);
- }else{
- $('#cfname_error').fadeOut(500);
- }
- if(cmname.length == 0){
- var error = true;
- $('#cmname_null').fadeIn(500);
- }else{
- $('#cmname_null').fadeOut(500);
- }
- if(!cmname.match(/^[a-zA-Z]*$/)){
- var error = true;
- $('#cmname_error').fadeIn(500);
- }else{
- $('#cmname_error').fadeOut(500);
- }
- if(caddress.length == 0){
- var error = true;
- $('#caddress_null').fadeIn(500);
- }else{
- $('#caddress_null').fadeOut(500);
- }
- if(!caddress.match(/^[a-zA-Z0-9 #-]*$/)){
- var error = true;
- $('#caddress_error').fadeIn(500);
- }else{
- $('#caddress_error').fadeOut(500);
- }
- if(email.length == 0 || email.indexOf('@') == '-1'){
- var error = true;
- $('#email_error').fadeIn(500);
- }else{
- $('#email_error').fadeOut(500);
- }
- if(subject.length == 0){
- var error = true;
- $('#subject_error').fadeIn(500);
- }else{
- $('#subject_error').fadeOut(500);
- }
- if(message.length == 0){
- var error = true;
- $('#message_error').fadeIn(500);
- }else{
- $('#message_error').fadeOut(500);
- }
- // If there is no validation error, next to process the mail function
- if(error == false){
- // Disable submit button just after the form processed 1st time successfully.
- $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
- /* Post Ajax function of jQuery to get all the data from the submission of the form as soon as the form sends the values to email.php*/
- $.post("email.php", $("#contact_form").serialize(),function(result){
- //Check the result set from email.php file.
- if(result == 'sent'){
- //If the email is sent successfully, remove the submit button
- $('#submit').remove();
- //Display the success message
- $('#mail_success').fadeIn(500);
- }else{
- //Display the error message
- $('#mail_fail').fadeIn(500);
- // Enable the submit button again
- $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
- }
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment