Show message after sending

How can I display a warning after the user clicks the submit button on the form?

I want the warning to appear when the page loads after clicking the submit button.

Is there any way to do this?

EDIT:

I need the message to be the HTML text displayed on the page, and not a javascript warning.

+3
source share
4 answers

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 Suitable for the new OP criterion at the 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 this for size.

+3
source

, JQuery AJAX. , , :

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


... 

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

, - .

, HTML JavaScript ( ) , - .

, , , PHP.

0
<?php

echo "<html>
<head>
</head>";

if($_POST['submit']){
     echo 'The form was submitted!";
} else {
    echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST"><input type="submit" name="submit" value="Submit">';
}

echo "</html>";

?>
0

Since you are submitting back to the same page, a cleaner and more modern way to do this would be to use jQuery to submit the form using AJAX. Then you can specify a callback method that will update the container on the page to display the state change:

0
source

Source: https://habr.com/ru/post/1783160/


All Articles