Здравствуйте. Есть форма и скрипт JS. Все работает. Но как сделать, чтобы при нажатии на кнопку отправить, если все правильно было заполнено - то js перенаправлял на обработчик PHP.
Форма-> Проверка данных-> Все поля заполнены->Обработчик->Страница благодарности.
Скрипт:
Форма:
Форма-> Проверка данных-> Все поля заполнены->Обработчик->Страница благодарности.
Скрипт:
| Код |
|---|
// JavaScript Document
$(document).ready(function(){
$(".various").fancybox({
maxHeight : 600,
fitToView : false,
width : '90%',
height : 'auto',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
$('.coupon').click(function() {
var code = prompt('Введите код купона', '');
if(!code) return;
$.post('/', {coupon: 1, offer: offer_id, code: code}, function(r) {
if(r.success) {
offer_id = r.offer_id;
if(r.curr == 'RUB') r.curr = 'руб.';
if(r.curr == 'UAH') r.curr = 'грн.';
$('.coupon').html('Стоимость по купону: ' + r.price + ' ' + r.curr);
$('.price-rw').html(r.price + ' ' + r.curr);
} else {
alert(r.message);
}
}, 'json');
});
$('.bottom-form .submit').bind('click', function() {
$('.order-form .fio').val($('.bottom-form .fio').val());
$('.order-form .addr').val($('.bottom-form .addr').val());
$('.order-form .tel').val($('.bottom-form .tel').val());
window.scrollTo(0, 550);
$('.order-form .submit').click();
});
$('.center-form .submit').bind('click', function() {
$('.order-form .fio').val($('.center-form .fio').val());
$('.order-form .addr').val($('.center-form .addr').val());
$('.order-form .tel').val($('.center-form .tel').val());
window.scrollTo(0, 550);
$('.order-form .submit').click();
});
$('.order-form .submit').bind('click', function() {
if(!$('.order-form .fio').val()) {
alert('Вы не указали Фамилию, Имя или Отчество!');
$('.order-form .fio').focus();
return;
}
if(!$('.order-form .addr').val()) {
alert('Вы не указали Адрес доставки!');
$('.order-form .addr').focus();
return;
}
if(!$('.order-form .tel').val()) {
alert('Вы не указали Телефон!');
$('.order-form .tel').focus();
return;
}
$('.order-form .submit').hide();
$('.order-form .loader').show();
$.post('/', {
order : 1,
//debug: 1,
//test: 1,
offer: offer_id,
cnt : 1,
fio : $('.order-form .fio').val(),
tel : $('.order-form .tel').val(),
addr: $('.order-form .addr').val(),
timezone: -(new Date().getTimezoneOffset()/60)
}, function(r) {
if(r.fail) {
alert(r.message);
} else if(r.success) {
location.href='finish';
//$('.cnt').val(1);
$('.fio').val('');
$('.addr').val('');
$('.tel').val('');
}
$('.order-form .loader').hide();
$('.order-form .submit').show();
}, 'json');
});
});
|
| Код |
|---|
<form class="order-form left" onsubmit="return false"> <span>Успейте купить фиксатор<br> Valgus Pro с 40% скидкой!</span> <input name="name" class="name fio" placeholder="Ваше ФИО" type="text"> <input name="address" class="address addr" placeholder="Адрес доставки" type="text"> <input name="phone" class="phone tel" placeholder="Контактный телефон" type="text"> <button name="button" type="submit" class="submit" onsubmit="return false">Заказать сейчас</button> <button name="button" type="submit" class="loader" onsubmit="return false" style="display:none">Ждите...</button> </form> |
