Answer the question
In order to leave comments, you need to log in
How to show a popup window after submitting a form?
I have a form that sends a username and a comment. This is all done with phpmailer. In my case, after submitting the form, I am "thrown" to the main page of the site. This piece of code looks like this:
if (!$mail->send()) {
echo 'Error';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
header('location: ../index.html');
}
function myFunction()
{
alert("Спасибо! Ваше сообщение отправлено");
}
Answer the question
In order to leave comments, you need to log in
You are confusing sending a Header and opening a popup with JS.
If you want it faster - do it
<?php
header("Location: /index.php?formsubmit");
<?php
if(isset($_GET['formsubmit'])) echo "<script>alert('Форма отправлена!');</script>";
<input type="submit" onclick="alert('Форма отправлена');return true;" value="Отправить">
The question, although it conveys the essence, does not speak about the conditions of your code.
By clicking on send mail, do you go to the page with the script, or call ajax, which sends sending emails without reloading the page?
If a redirect occurs by clicking on sending mail, then the task cannot be done.
If you make an ajax request, then if successful, you must return some response, which then needs to be parsed and a window with the result is already generated there, for example, using jquery
$.post(
'someUrl',
{
mailAddress: 'someAddress',
mailTitle: 'someTitle',
mailText: 'someText'
},
function (response) {
if (response === 1){
alert("Спасибо! Ваше сообщение отправлено");
} else {
alert("Во время отправки произошла ошибка. Ошибка: " + response);
}
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question