Вот скрипт js под него нужен скрипт обработчик. В форме 3 поля name, phone, mail. Нужен скрипт обработчик. Исполнителя выберу по самой низкой стоимости.
$('.send-button').click(function() {
var data = {};
$(this).parent().siblings('input, textarea').each(function() {
var name = $(this).prop('name');
var value = $(this).val();
var valid = true;
switch (name) {
case 'email':
valid = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/.test(value);
break;
default:
valid = value && value !== $(this).attr('placeholder');
}
if (valid)
data[name] = value;
else
$(this).addClass('error');
});
if ($(this).parent().siblings('.error').length)
return;
$.ajax({
url: '/send',
method: "POST",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json"
})
.success(function(e) {
alert('Сообщение отправлено, спасибо!');
})
.error(function() {
alert(Простите, что-то пошло не так :(');
});
}).each(function() {
$(this).parents('form').keypress(function(e) {
if ($(e.target).is('input, textarea'))
return;
if (e.which === 13)
$(this).find('.send-button').click();
}).children().focus(function() {
$(this).removeClass('error');
});
});
Опубликован 11.08.2016 в 15:38