0

I have a problem where I want to reload the page on submit. I did this with the simple script function shown below. However, the echo'd "hello" does not disappear when I reload. Is there a reload function that changes the state of my submit post, and the "hello" is no longer appearing.

<!DOCTYPE html>
<html lang="en">
<body>
<form method="post">
    <button class="btn-login" type="submit" name="submit">Sign in</button>
</form>

<?php
if (isset($_POST['submit'])) {
    echo "hello";
    echo "<script>window.location.reload(true)<script>";
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Gijzy
  • 102
  • 9
  • What are you trying to achieve here really? The example is so oversimplified as to be meaningless. I can't really work out why you'd want to submit a form, then immediately after returning the response you then reload the whole page...for what purpose? If you want to show something to the user you can do it immediately after submitting the form, in the same request. – ADyson May 06 '22 at 21:02

1 Answers1

1

If you want to redirect to a new page (or even the same page) but without POST values, then use

window.location.replace(url)

https://developer.mozilla.org/en-US/docs/Web/API/Location/replace

Kadet
  • 1,344
  • 3
  • 10