I would like to use the PRG pattern to prevent form-resubmission, because the submission involves sending a mail. The problem with this approach though, is that I don't seem to find the "right" way to show the user what data has been sent after the redirect. Currently I am doing something like:
Some page with the form (index.html
)
<form action="handleform.php" method="post">
<input type="text" name="name" placeholder="Name" required />
<input type="text" name="tel" placeholder="Telephone" />
<input type="email" name="mail" placeholder="E‑Mail" required />
<!-- and more input fields -->
</form>
Some script handleform.php
that handles the form data
<?php
$data[0] = filter_var(INPUT_POST, "name", FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[1] = filter_var(INPUT_POST, "tel", FILTER_SANITIZE_NUMBER_INT);
$data[2] = filter_var(INPUT_POST, "mail", FILTER_VALIDATE_EMAIL);
// process rest of data and create mail
$mail->Body = getNiceHTML($data);
$mail->send();
header("Location: formhandled.php?id=" . urlencode($mail->Body));
exit();
?>
and a scripted page formhandled.php
to display upon success
<!-- header and menu html -->
<?php
echo $_GET["id"];
?>
<!-- footer html -->
The problem with this approach is that I got the idea that this exposes all the entered data in the URL and thus might be too vulnerable. On top of that, the HTML-string makes the URL rather lengthy. I could think of two other approaches to solve my problem
- Store the string in a (temporary) file and pass the filename, but then I would need to find some way to delete these files after I left the
formhandled.php
in order to prevent that this information stays on the server longer than necessary. - Start a session. The main problem with this approach is that I could only display the data if the user did not disable cookies (if I understood that correctly).
but I don't see why these would be better/worse. I also can't imagine that no-one ever did something like this, but I couldn't find anything on how this problem is solved.
Therefore my question: how to display the entered form data after redirecting?