PHP Post Request Refreshes

Question:
I’m making a form and when I use POST the target page refreshes and I lose the result. If you look quick you can see the correct output display correctly. GET works fine with no issues. POST works fine when you pop out the webpage into a new tab but not within Replit.


Repl link:


index.php

<html>
  <head>
    <title>Countdown!</title>
  </head>
  <body>
   <h1>Countdown Timer</h1>
<form method="post" action="countdown.php">
  <label for="date">Pick a Date:</label>
  <input type="date" id="date" name="date">
  <input type="submit" value="Submit">
</form>
  </body>
</html>

countdown.php

<html>
<head>
  <title>Countdown Results</title>
</head>
<body>
<?php
// $dateInfo = filter_input(INPUT_GET,"date");
$dateInfo = $_POST["date"];
$parsedDate = date_parse($dateInfo);

$time = mktime(0,0,0,$parsedDate['month'],$parsedDate['day'],$parsedDate['year']);
$today = time();
$difference = ($time - $today);
$days = (int)($difference/86400);
print "Our event will occur in $days days";

?>
</body>
</html>
1 Like

Hey there! Welcome to the community!

1 Like

Bump! 200 Cycles for a solution.

5 Likes

It seems, for some reason, after the POST request (on form submission) a GET request is being made refreshing the page meaning there are no POST values to access so your getting -today/86400… But you already figured that part out. It isn’t your countdown.php file, since I commented out all the PHP and the page was still refreshed…

Edit: I’ve tried updating the PHP version to the latest stable version available on Nix, v8.2.0RC7 to no avail.

It seems PHP web servers are somehow ‘statically’ hosted by Replit, and the issue likely lies in that hosting.

2 Likes

it’s an issue with the developer tools
https://88634dee-91d2-42ca-abcb-24687c89e7aa.id.repl.co/__replco/devtools_wrapper.html

2 Likes

Thank you, is there a work around?

I managed to get it to work if you setup your post request from a file that isn’t the index.php file. And then it only works if I popout the webpage to a new tab.

index.php

<html>
  <head>
    <title>PHP Test</title>
  </head>
  <body>
<a href="newfile.php">link</a>
   
  </body>
</html>

newfile.php

<html>
  <head>
    <title>PHP Test</title>
  </head>
  <body>
    <?php echo '<p>Hello World</p>'; 
?> 
<form method="POST" action="/formprocess.php">
<input type="text" name="name">
  <input type="submit">
</form>
   
  </body>
</html>

formprocess.php

<?php
if( isset($_POST['name']) ){
  $name = $_POST["name"];
}


echo 'Hello ' . $name . '!';
?>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

still an issue