Where you have:

header('location:page1.php');

append a variable on the location, like:

header('location:page1.php?status=success');

And on page1.php, do something like:

if( $_GET['status'] == 'success'):
    echo 'feedback message goes here';
endif;
Answer from pbs on Stack Overflow
🌐
SitePoint
sitepoint.com › php
I want to display success message after form submission without changing URL - PHP - SitePoint Forums | Web Development & Design Community
July 26, 2013 - I will be very glad if I can get a tip on how I can display success message after form submission with changing URL in PHP…just the idea to start off
People also ask

wordpress display success message after form submit
Here's a simple way to show a success message after someone submits a form on your WordPress site. How It Works: When someone submits the form, the code checks if the form was actually submitted by looking for a specific button click. It uses a nonce (a security token) to make sure the submission is secure and genuine. Once the form is processed, a transient (a temporary message) is set to indicate success. The page then redirects to prevent the form from being submitted again if the user refreshes the page. Displaying the Message: In the footer of your site, the cod
🌐
wp-dude.com
wp-dude.com › code-snippet › display-success-message-after-form-submission
Display Success Message After Form Submission in WordPress
how to add success message after form submit in wordpress
Here's a simple way to show a success message after someone submits a form on your WordPress site. How It Works: When someone submits the form, the code checks if the form was actually submitted by looking for a specific button click. It uses a nonce (a security token) to make sure the submission is secure and genuine. Once the form is processed, a transient (a temporary message) is set to indicate success. The page then redirects to prevent the form from being submitted again if the user refreshes the page. Displaying the Message: In the footer of your site, the cod
🌐
wp-dude.com
wp-dude.com › code-snippet › display-success-message-after-form-submission
Display Success Message After Form Submission in WordPress
wordpress form submission success message display
Here's a simple way to show a success message after someone submits a form on your WordPress site. How It Works: When someone submits the form, the code checks if the form was actually submitted by looking for a specific button click. It uses a nonce (a security token) to make sure the submission is secure and genuine. Once the form is processed, a transient (a temporary message) is set to indicate success. The page then redirects to prevent the form from being submitted again if the user refreshes the page. Displaying the Message: In the footer of your site, the cod
🌐
wp-dude.com
wp-dude.com › code-snippet › display-success-message-after-form-submission
Display Success Message After Form Submission in WordPress
Top answer
1 of 5
6

try this way . try to send mail from an ajax . Please write your code like below

javascript

    <script type="text/javascript">
    function sendEnquiryform(){
        var name=$('#name').val();
        var email=$('#email').val();
        var message=$('#message').val();
        $.post("send_mail.php",'name='+name+'&email='+email'&message='+message,function(result,status,xhr) {
                if( status.toLowerCase()=="error".toLowerCase() )
                { alert("An Error Occurred.."); }
                else { 
                    //alert(result);
                    $('#sucessMessage').html(result);
                }
            })
            .fail(function(){ alert("something went wrong. Please try again") });
    }
</script>

Your html

<form method="post" name="FrmEnquiry" id="FrmEnquiry" action="" onsubmit="sendEnquiryform();">
    <input name="name" id="name" required="required" placeholder="Your Name">
    <input name="email" id="email" type="email" required="required" placeholder="Your Email">

    <div class="clearfix"> </div>
    <textarea name="message" id="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
    <div class="submit">
        <input id="submit" name="submit" type="submit" value="Submit">
    </div>
</form>

<span id="sucessMessage"> </span>

send_mail.php

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: agriindiaexp.com'; 
    $to = '[email protected]'; 
    $subject = 'Email Inquiry';

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if ($_POST['submit']) {
        if (mail (subject, $body, $from)) { 
           $success = "Message successfully sent";
        } else {
            $success = "Message Sending Failed, try again";
        }
    }
?>

this will display your message in your page.Please try this. This is working fine in my case.

2 of 5
3

You could post the form to the same page and check for a success message there, like this.

<?php

if ($_POST['submit']) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: agriindiaexp.com'; 
    $to = '[email protected]'; 
    $subject = 'Email Inquiry';

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    if (mail (subject, $body, $from)) { 
       $success = "Message successfully sent";
    } else {
        $success = "Message Sending Failed, try again";
    }
}
?>

...other html....

<div id="message"><?php if(isset($success)){ echo $success; } ?></div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input name="name" required="required" placeholder="Your Name">
    <input name="email" type="email" required="required" placeholder="Your Email">

    <div class="clearfix"> </div>
    <textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
    <div class="submit">
        <input id="submit" name="submit" type="submit" value="Submit">
    </div>
</form>

...other html....
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 298777 › after-form-submission-want-to-show-success-message-in-the-form-page
plugins - After form submission want to show success message in the form page - WordPress Development Stack Exchange
<form action="<?php echo ...ucts&message=success')); } ... You need to pass the variable and its value in GET method to display the success message which you're already doing....
🌐
Stack Overflow
stackoverflow.com › questions › 66551098 › how-can-i-display-the-message-sent-successful-after-completing-the-form
php - How can I display the "Message sent successful" after completing the form - Stack Overflow
<?php if(isset($_POST) { $name = $_POST['name2']; $email = $_POST['email2']; $formcontent="From: $name \nEmail: $email"; $recipient = "[email protected]"; $subject = "Website Under Construction"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); // Set the message here: $message = "Message sent!"; } ?> <form action="contact.php" id="footer-form" method="post" role="form"> <div class="form-group has-feedback"><label class="sr-only" for="name2">Name</label> <input class="form-control" id="name2" name="name2" placeholder="Name" required=""
🌐
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 - <?php // (A) PROCESS THE FORM // process($_POST["name"], $_POST["email"]); // (B) THEN SET THE RESPONSE MESSAGE $message = "SUCCESSFUL!"; // $message = "FAILURE!";
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Displaying message after submit data - JavaScript
January 3, 2019 - I have my form html form, i want to display success or failure message to the page…when data is inserted to the database… i am using php to connect and send data to the database… need your help bellow are my codes: html page A small example page to insert some data in to the MySQL database ...
🌐
Stack Overflow
stackoverflow.com › questions › 49274153 › display-success-message-after-form-submission-in-php
Display success message after form submission in PHP
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>'; } }
🌐
Wp-dude
wp-dude.com › code-snippet › display-success-message-after-form-submission
Display Success Message After Form Submission in WordPress
December 20, 2024 - Save the changes to the functions.php file. To display the form on a page or post, use the shortcode [wp_dudecom_form] in the WordPress editor where you want the form to appear. Test the form submission by filling it out and submitting it.
Published   Dec 20, 2024
Author   123
🌐
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
July 25, 2023 - <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>
🌐
Stack Overflow
stackoverflow.com › questions › 52886405 › after-form-submit-success-message-display
After form submit success message display
`if ($nameErr == '' && $emailErr == '' && $pwdErr == '' && $phErr == '' && $genderErr == '') { echo '<div class="msg_success" style="visibility: visible!important;">'.'</div>'; }` I newbie to the PHP. Can anyone suggest me what I'm doing wrong here and point me in the right direction.
🌐
SitePoint
sitepoint.com › php
Display success message when form is submitted - PHP - SitePoint Forums | Web Development & Design Community
March 20, 2019 - ); $error_id = isset($_GET['request_status']) ? $_GET['request_status'] : 0; // echo $error_id; ?> <!-- Reset password validation msg --> <?php if ( $error_id !== 0 ): ?> <div class="alert alert-success" > <strong> <?php echo $errors[$error_id]; ?></strong> </div> <?php endif ?> By saving it in the sessions and unset the session afterwards
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.

🌐
Stack Overflow
stackoverflow.com › questions › 49461355 › after-form-submission-want-to-show-success-message-in-the-form-page
php - After form submission want to show success message in the form page - Stack Overflow
<form action="<?php echo admin_url('admin-post.php') ?>" method="post"> <table> <input type="hidden" name="action" value="add_product_from_admin"> <tr><td>Name</td><td><input type="text" name="pr_name" id="pr_name"></td></tr> <tr><td colspan="2" align="center"><input type="submit" name="pr_submit" id="pr_submit" value="Save Products"></td></tr> </table> </form> add_action( 'admin_post_add_product_from_admin', 'add_product_into_data_base' ); function add_product_into_data_base() { //some database operations wp_redirect(admin_url('admin.php?page=add-products&message=success')); }
🌐
Wpmet
wpmet.com › doc › display-success-message-after-form-submit-metform
Display Success Message After Form Submit-Sweet Alert
June 28, 2022 - Want to display success message after form submit? then check out this easy technique with MetForm. Basically, a sweet alert makes an alert box more attractive.
Price   $$$
Address   2nd Floor, Amigo 14 Square, House No: 59/C-61/C, 2A Asad Ave, Dhaka, 1207
🌐
SitePoint
sitepoint.com › php
Display "Form sent successfully!" on same page of the form after form submission - PHP - SitePoint Forums | Web Development & Design Community
February 28, 2018 - I’m working on a contact form. It’s working fine. User fills up contact form, processed by PHP, if successful, the user will be redirected to a thank you page then will redirect back to the main webpage after 3 or so se…
🌐
PHPpot
phppot.com › jquery › jquery-fade-out-message-after-form-submit
jQuery Fade Out Message after Form Submit - PHPpot
<script> $("#frmDemo").submit(function(e) { e.preventDefault(); var name = $("#name").val(); var comment = $("#comment").val(); if(name == "" || comment == "" ) { $("#error_message").show().html("All Fields are Required"); } else { $("#error_message").html("").hide(); $.ajax({ type: "POST", url: "post-form.php", data: "name="+name+"&comment="+comment, success: function(data){ $('#success_message').fadeIn().html(data); setTimeout(function() { $('#success_message').fadeOut("slow"); }, 2000 ); } }); } }) </script>