JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input type="hidden" name="Форма" value="Оставьте заявку!">
<input type="text" name="Имя">
<input type="text" id="phone" name="Телефон" required>
<button type="submit">Отправить</button>
</form>
JavaScript
//E-mail Ajax Send
$("form").attr('novalidate', 'novalidate').submit(function(e) {
e.preventDefault(); // запретить отправку формы
var form = $(this);
if($.trim($('#phone').val()).length == 0) {
alert('Заполните поле!');
return;
}
$.ajax({
type: "POST",
url: "mail.php", //Change
data: form.serialize()
}).done(function() {
alert("Thank you!");
setTimeout(function() {
// Done Functions
form.trigger("reset");
}, 1000);
});
});