Я пытаюсь сделать всплывающее окно подтверждения перед отправкой формы. Но это не работает. Я использую Sweet Alert 2.
document.querySelector('#order').addEventListener('submit', function(e) {
var form = $(this).parents('form');
e.preventDefault();
swal({
title: "Are you sure?",
text: "Once a invoice is created, you will not be able to delete without the help of support",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, I am sure!',
cancelButtonText: "No, cancel it!",
}).then(function() {
swal({
title: 'Success!',
text: 'Invoice created! Go to the invoice tab to pay it.',
type: 'success'
}, function() {
form.submit();
});
},function(dismiss) {
if(dismiss == 'cancel') {
swal("Cancelled", "Invoice not created!", "error");
}
});
});
Это мой код Javascript, и мой код PHP выглядит примерно так
<?php
if(isset($_POST['k'])
{
header('Location: https://google.com');
}
?>
Мой HTML-код
<form method="POST">
<button type="submit" name="k"></button
</form>
Не работает почему?
Обновлять
$("#order").on('submit', function(e) {
var form = $(this);
e.preventDefault();
swal({
title: "Are you sure?",
text: "Once a invoice is created, you will not be able to delete without the help of support",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, I am sure!',
cancelButtonText: "No, cancel it!",
}).then(function() {
swal({
title: 'Success!',
text: 'Invoice created! Go to the invoice tab to pay it.',
type: 'success'
}, function() {
$(this).trigger('submit');
});
},function(dismiss) {
if(dismiss == 'cancel') {
swal("Cancelled", "Invoice not created!", "error");
}
});
});
Также я забыл добавить, что я проанализировал этот код, и в моем фактическом коде есть есть идентификатор в форме
Под неработающим я подразумеваю, что данные не публикуются. Если он работает правильно, он должен перенаправлять на google.com в соответствии с кодом PHP.