Home › Forums › Porto – Responsive HTML5 Template › Contact Form
- This topic has 3 replies, 2 voices, and was last updated 1 month, 2 weeks ago by Support. This post has been viewed 204 times
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
November 28, 2024 at 9:30 am #10045415middlemannParticipant
Hey Guys,
The contact form is working great (sending mail) but, on page it is throwing the Error message, “Error! There was an error sending your message.”
November 28, 2024 at 10:10 pm #10045416SupportKeymasterHi, looks like the way that server returns the success status is different, so open the file js/views/view.contact.js and change line 88
FROM:
if (data.response == 'success') {
TO:
if (data.response == 'success' || data.response == 200 || data.response == '200') {
November 30, 2024 at 4:05 pm #10045429middlemannParticipanti changed the code as instructed – still getting the error message in the browser
December 2, 2024 at 7:02 am #10045431SupportKeymasterReplace js/views/view.contact.js with this;
/* Name: View - Contact Written by: Okler Themes - (http://www.okler.net) Theme Version: 10.0.0 */ (function($) { 'use strict'; /* Custom Rules */ // No White Space $.validator.addMethod("noSpace", function(value, element) { if( $(element).attr('required') ) { return value.search(/^(?! *$)[^]+$/) == 0; } return true; }, 'Please fill this empty field.'); /* Assign Custom Rules on Fields */ $.validator.addClassRules({ 'form-control': { noSpace: true } }); /* Contact Form: Basic */ $('.contact-form').each(function(){ $(this).validate({ errorPlacement: function(error, element) { if(element.attr('type') == 'radio' || element.attr('type') == 'checkbox') { error.appendTo(element.closest('.form-group')); } else if( element.is('select') && element.closest('.custom-select-1') ) { error.appendTo(element.closest('.form-group')); } else { if( element.closest('.form-group').length ) { error.appendTo(element.closest('.form-group')); } else { error.insertAfter(element); } } }, submitHandler: function(form) { var $form = $(form), $messageSuccess = $form.find('.contact-form-success'), $messageError = $form.find('.contact-form-error'), $submitButton = $(this.submitButton), $errorMessage = $form.find('.mail-error-message'), submitButtonText = $submitButton.val(); $submitButton.val( $submitButton.data('loading-text') ? $submitButton.data('loading-text') : 'Loading...' ).attr('disabled', true); // Fields Data var formData = $form.serializeArray(), data = {}; $(formData).each(function(index, obj){ if( data[obj.name] ) { data[obj.name] = data[obj.name] + ', ' + obj.value; } else { data[obj.name] = obj.value; } }); // Google Recaptcha v2 if( data["g-recaptcha-response"] != undefined ) { data["g-recaptcha-response"] = $form.find('#g-recaptcha-response').val(); } // Ajax Submit $.ajax({ type: 'POST', url: $form.attr('action'), data: data }).always(function(data, textStatus, jqXHR) { $errorMessage.empty().hide(); if (data.response == 'error') { $errorMessage.html(data.errorMessage).show(); $messageError.removeClass('d-none'); $messageSuccess.addClass('d-none'); if (($messageError.offset().top - 80) < $(window).scrollTop()) { $('html, body').animate({ scrollTop: $messageError.offset().top - 80 }, 300); } $form.find('.has-success') .removeClass('has-success'); $submitButton.val( submitButtonText ).attr('disabled', false); } else { // Uncomment the code below to redirect for a thank you page // self.location = 'thank-you.html'; $messageSuccess.removeClass('d-none'); $messageError.addClass('d-none'); // Reset Form $form.find('.form-control') .val('') .blur() .parent() .removeClass('has-success') .removeClass('has-danger') .find('label.error') .remove(); if (($messageSuccess.offset().top - 80) < $(window).scrollTop()) { $('html, body').animate({ scrollTop: $messageSuccess.offset().top - 80 }, 300); } $form.find('.form-control').removeClass('error'); $submitButton.val( submitButtonText ).attr('disabled', false); return; } }); } }); }); }).apply(this, [jQuery]);
Make sure to clear cache of the browser.
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
This topic is marked as "RESOLVED" and can not rceive new replies.