@vetaliy_net

Почему не работает форма обратной связи?

Не работает форма обратной связи при нажатии страница просто обновляется html шаблон c themeforest

Код на странице
$(document).ready(function() {
	try {
		jQuery("#contactForm").validate({
			submitHandler: function() {
				var postvalues =  jQuery("#contactForm").serialize();
				//alert(postvalues);	
				jQuery.ajax
				 ({
				   type: "POST",
				   url: "contact/process-form.php",
				   data: postvalues,
				   success: function(response)
				   {
					 jQuery("#status").html(response).show('normal');
					 jQuery('#inputMessage, #inputEmail, #inputName').val("");
				   }
				 });
				return false;
				
			},
			focusInvalid: true,
			focusCleanup: false,
			//errorLabelContainer: jQuery("#registerErrors"),
			rules: 
			{
				inputName: {required: true},
				inputEmail: {required: true, minlength: 6,maxlength: 50, email:true},
				inputMessage: {required: true, minlength: 6}
			},
			
			messages: 
			{
				inputName: {required: "This field is required"},
				inputEmail: {required: "This field is required", email: "Please provide a valid e-mail"},
				inputMessage: {required: "This field is required"}
			},
			
			errorPlacement: function(error, element) 
			{
				error.insertBefore(element);
				jQuery('<span class="errorarr"></span>').insertBefore(element);
			},
			invalidHandler: function()
			{
				//jQuery("body").animate({ scrollTop: 0 }, "slow");
			}
				
		});		
	} catch ( err ) {
		alert("Something went wrong, please check the settings in contact/contact.php file.");
	}
	});


Кот в process-form.php
<?php


//If the form is submitted
if(isset($_POST['send'])) {
  
	$email= 'vitalkapp@yandex.ua';
	$message = 'Message site';

	$contactName = stripslashes(trim($_POST['inputName']));
	$subject = stripslashes(trim($_POST['inputSubject']));
	if(!$subject) $subject = 'No Subject';
	//If there is no error, send the email
	if(!isset($hasError)) {
		if(trim($_POST['inputName']) === '') {
			$nameError = 'You forgot to enter your name.';
			$hasError = true;
		} 
		else {
			$contactName = trim($_POST['inputName']);
		}
		
		//Check to make sure sure that a valid 
		//address is submitted
		if(trim($_POST['inputEmail']) === '')  {
			$emailError = 'You forgot to enter your email address.';
			$hasError = true;
		} else if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", trim($_POST['inputEmail']))) {
            $emailError = 'You entered an invalid email address.';
            $hasError = true;
		} else {
			$email = trim($_POST['inputEmail']);
		}
		 
		//Check to make sure comments were entered 
		if(trim($_POST['inputMessage']) === '') {
			$messageError = 'You forgot to enter your message.';
			$hasError = true;
		} 
		else {
			if(function_exists('stripslashes')) {
		  		$message = stripslashes(trim($_POST['inputMessage']));
		 	} 
		 	else {
		  		$message = trim($_POST['inputMessage']);
			}
		}
	}
	if(!isset($hasError)) {
		
		$status = "";
		
		require_once "class.phpmailer.php";
		$mail = new PHPMailer();
		$mail->IsMail();
		$mail->IsHTML(true);    
		$mail->CharSet  = "utf-8";
		$mail->From     = $email;
		$mail->FromName = $contactName;
		$mail->WordWrap = 50;    
		$mail->Subject  =  $subject;
		$mail->Body     =  "<strong>Full Name:</strong> " . $contactName. ".<br/>";
		$mail->Body     .= "<strong>Message:</strong> " . $message. ".";
		$mail->AddAddress('mail');
		$mail->AddReplyTo($email);
		
		if(!$mail->Send()) {  // send e-mail
			$status =  '<div class="alert alert-danger fade in">Failed to send your e-mail. Please check everything and try again.</div>';
		}
		else
		{
			$status =  '<div class="success fade-in">E-mail was sent successfully.</div>';
		}
		echo $status; die();
		
		
	}
	else 
	{
		die ("Something went wrong, please check all the settings.");
	}	

	die;
} 
?>


Код из class.phpmailer.php
  • Вопрос задан
  • 252 просмотра
Пригласить эксперта
Ответы на вопрос 2
@McBernar
Jquery подключен?
Сообщение из формы до скрипта доходит?
Какой response возвращает?

Вы предлагаете нам тут на кофейной гуще погадать?
Ответ написан
Комментировать
event.preventDefault ?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
28 мар. 2024, в 18:16
1000 руб./за проект
28 мар. 2024, в 18:15
90000 руб./за проект
28 мар. 2024, в 18:05
5000 руб./за проект