I have a website that uses seperate files to process the PHP like the post form is on one page and when a user submits the form, it goes to contact_form.php then when the PHP has processed the form, it will redirect the user with this part of the code:
// rest of code above
if($result)
{
$_SESSION['SUCCESS'] = "Your message was posted";
header("Location: viewtopic.php?id=" . $id . "&mode=view");
}
else
{
$_SESSION['ERROR'] = "Your message could not be posted";
header("Location: viewtopic.php?id=" . $id . "&mode=add");
}
Since the else part would return to the posting page and the values that were submitted would be empty in the input fields, I need them intact when an error has returned…
I wouldn’t rely on JavaScript validation since users may have them disabled, so I have no idea would be the best method for me to use when returning with errors and the values are intact in the input fields.
You can put those post values in session variables as well and fill the form again in case of error. May be something like this: