After long researching, I found solution to delay the alert message with jQuery delay() function, the delay allowing the HTML page load and then execute the alert. Thanks to all who helped me to get to this result.

  <script>
      $(document).ready(function(){
          setTimeout(function() {
              <?php
              if( $_GET['status'] == 'success') {
                  echo 'alert("welldone");';
              }
              else{
                  echo 'alert("no good");';
              }
              ?>
              }, 500);
      });
  </script>
Answer from Yotam Dahan on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-pop-an-alert-message-box-using-php
How to Pop an Alert Message Box using PHP? - GeeksforGeeks
July 12, 2025 - <?php // PHP program to pop an alert // message box on the screen // Function definition function function_alert($message) { // Display the alert box echo "<script>alert('$message');</script>"; } // Function call function_alert("Welcome to Geeks for Geeks"); ?>
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ web-development โ€บ threads โ€บ 371318 โ€บ javascript-alert-after-post-submit-with-php
javascript alert after post submit with php.
If you need the alert to appear only after the POST completes and the page reloads, render the message on the server and then trigger alert on load. Two common pitfalls that can produce a blank alert in Firefox are: injecting raw strings into ...
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ alert in php: displaying an alert message box in php
Alert in PHP: Displaying An Alert Message Box in PHP
January 26, 2025 - Deep dive into alert in PHP tutorial and learn how to display an โš ๏ธ alert message box in PHP, types of pop-up boxes with examples. Start learning now!
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
YouTube
youtube.com โ€บ watch
Part 20: PHP-Admin: How to show success message on form submit using sweet alert in php - YouTube
Complete PHP Blog Admin Panel (28 Parts) - Better Tutorialhttps://www.youtube.com/watch?v=yK-AfMxCq5A&list=PLRheCL1cXHrvKqYXmyArH55g5VkPhpzzPHere, in this vi...
Published ย  April 7, 2020
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ php alert
PHP alert - Scaler Topics
April 1, 2024 - In this example, after a successful user registration process, an alert dialog box is displayed to the user with a success message. Run the above code in your editor for a better and clear explanation. ... In this case, if a user enters incorrect login credentials, an alert dialog box is triggered to display an error message. Run the above code in your editor for a better and clear explanation. ... In this example, when a form is submitted, PHP checks if the username field is empty.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ php-alert
PHP alert - javatpoint
PHP alert with examples, php file, php session, php date, php array, php form, functions, time, xml, ajax, php mysql, regex, string, oop, addslashes(), addcslashes() etc.
Top answer
1 of 4
4

pagewithform.php

<html>
  <head>
  ...
  </head>
  <body>
    ...
    <form action="myformsubmit.php" method="POST">
      <label>Name: <input type="text" name="name" /><label>
      <input type="Submit" value="Submit" />
    </form>
    ...
  </body>
</html>

myformsubmit.php

<html>
  <head>
  ....
  </head>
  <body>
    <?php if (count($_POST)>0) echo '<div id="form-submit-alert">Form Submitted!</div>'; ?>
    ...
  </body>
</html>

EDITED Fits new critieria of OP on last edit.

EDITv2 Try it at home!

<html>
  <head>
    <title>Notify on Submit</title>
  </head>
  <body>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
      <label>Name: <input type="text" name="name" /></label>
      <input type="submit" value="Submit" />
    </form>
    <?php if (count($_POST)>0) echo "Form Submitted!"; ?>
  </body>
</html>

Try that on for size.

2 of 4
2

Since you're submitting back to the same page, a cleaner and more modern way of doing this would be to use JQuery to submit the form using AJAX. You can then specify a callback method that will update a container on the page to reflect the change in state:

$('#myForm').submit(function() {
   $('#myResultDiv').text("Form submitted");
   return false;
});


... 

<div id="myResultDiv"></div>

This prevents the unnecessary reloading of the page, making your web application snappier and more responsive.

This also has the added benefit of keeping your HTML and JavaScript (content and behavior) separate, for which your web designers will thank you for.

This would work with just about any server-side platform, including but not limited to PHP.

Find elsewhere
๐ŸŒ
STechies
stechies.com โ€บ display-alert-message-box-dialogue-box-using-php
How to Display Alert Message Box in PHP?
<html> <head> <meta charset="utf-8"> <title>JavaScript Alert Box by PHP</title> <?php function_alert("We welcome the New World"); function function_alert($msg) { echo "<script type='text/javascript'>alert('$msg');</script>"; } ?> </head> <body> </body></html>
๐ŸŒ
YouTube
youtube.com โ€บ codinghero
How to show success message on form submit using sweet alert in php - YouTube
#html #css #php #mysql#phpcrudshow success message After Click Submit ButtonRegistration-Form Download :https://www.w3schools.com/howto/tryit.asp?filename=tr...
Published ย  November 30, 2022
Views ย  23K
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 49274153 โ€บ display-success-message-after-form-submission-in-php
Display success message after form submission in PHP
Part of PHP Collective ยท 0 ยท I have the following code. In this, I'm showing an alert message after sending the message through a form. I don't want to display the alert message with button. Is there any way I can show a success message without using an alert? if (isset($_POST['Submit_msg'])) { $mbno = $_POST['mobile']; $campaign_text = $_POST['campaign_text']; $save_sms_report = $db->sms_report($mbno,$campaign_text,$date,$homepage); if($save_sms_report){ echo '<script type="text/javascript">alert("Message sent successfully");</script>'; echo "<script>window.top.location='campaign-manager.php?url=checked'</script>"; //echo "<script>window.top.location='campaign-manager.php'</script>"; } else{ echo '<script type="text/javascript">alert("unable to send sms");</script>'; } } javascript ยท
๐ŸŒ
Code Boxx
code-boxx.com โ€บ home โ€บ 2 ways to display a message after submitting html form
2 Ways To Display A Message After Submitting HTML Form
May 1, 2024 - Create the HTML form as usual, and it will submit to itself (I.E. Submit to the same page). Do the processing when the form is submitted. The server-side script should generate a $message = "SYSTEM MESSAGE" upon completion and will display here.
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ php-form-processing-avoiding-a-new-page-for-errors
php form processing - avoiding a new page for errors... (Example) | Treehouse Community
August 24, 2015 - The real security validation has to happen on the server side that, after the user hits submit. I tend to do my validation checks, and if a check fails, alert on the input that failed, why it failed and repopulate the form with the rest of the data so the user doesn't have to fill the form out again. Nothing is more frustrating than that, right? The only other problem I see with your idea is from a UI, is that your error messages are disconnected from where the error happened.
๐ŸŒ
Tpoint Tech
tpointtech.com โ€บ php-alert
PHP alert - Tpoint Tech
March 17, 2025 - In this article, we will learn about the use of dialog boxes of JavaScript i.e., the alert box, confirmation box, and prompt dialog box in PHP.
๐ŸŒ
Stack Exchange
wordpress.stackexchange.com โ€บ questions โ€บ 417677 โ€บ how-to-show-a-message-after-submitting-a-form-form-made-using-plugin
php - How to show a message after submitting a form (form made using plugin) - WordPress Development Stack Exchange
<script> (function($) { $(document).ready(function() { $("#myForm").submit(function(e) { e.preventDefault(); // Check the nonce for security var formData = $(this).serialize(); formData += "&my_form_submission_nonce=" + $("#my_form_submission_nonce_field").val(); // Send the AJAX request $.ajax({ type: "post", url: $(this).attr("action"), data: formData, success: function(response) { console.log(response); $("#message").text(response); window.location.href = 'https://myawesomewebsite/thank-you-page'; }, error: function(jqXHR, textStatus, errorThrown) { $("#message").text("Error occurred: " + textStatus); } }); }); }); })(jQuery); </script>
๐ŸŒ
PHP Freaks
forums.phpfreaks.com โ€บ php coding โ€บ php coding help
[SOLVED] Popup Message after form submitted - PHP Coding Help - PHP Freaks
August 14, 2008 - Hello, I have this code and it displays messages after the form is submitted, how I would go about redirecting this to another page and a popup message saying successful. I believe it will be the IF statement at the end that I will need to update? Here is the code that I am using now;