Показать сообщение отдельно
  #9 (permalink)  
Старый 16.12.2013, 17:26
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

boot78,
<form name="order" method="post" action="./feedback.php">
	<input type="hidden" name="discount" value="35%">
	<input type="text" name="name" placeholder="Имя">
	<input type="text" name="email" placeholder="Email">
	<input type="text" name="phone" placeholder="Телефон">
	<input type="submit" value="Заказать звонок">
</form>

<script>
$(function() {
	$('form[name=order]').submit(function() {
		if (validateForm(this)) {
			$.ajax({
				type: this.method,
				url: this.action,
				data: $(this).serialize(),
				success: function() {
					$.fancybox({
						'type': 'ajax',
						'href': './ok.html'
					});
				}
			});
		}
		return false;
	});
});
function validateForm(theForm) {
	var regexp = /^[a-zёа-я]{3,20}$/i;
	if (!regexp.test(theForm.name.value)) {
		alert('Некорректное имя (от 3 до 20 букв)');
		theForm.name.focus();
		return false;
	}
	regexp = /^([\w-]+\.)*[\w-]+@[\w-]+(\.[\w-]+)*\.[a-z]{2,6}$/i;
	if (!regexp.test(theForm.email.value)) {
		alert('Некорректный адрес электронной почты');
		theForm.email.focus();
		return false;
	}
	regexp = /^[0-9]{7,16}$/;
	if (!regexp.test(theForm.phone.value)) {
		alert('Некорректный номер телефона (от 7 до 16 цифр)');
		theForm.phone.focus();
		return false;
	}
	return true;
}
</script>
Ответить с цитированием