I have been stuck up at the point of form data clearing. After the user submits a form the data is added to database. Its fine till here. But if the user refreshes the page previously entered data is re entered into the database. I am using post method to send the data. I am not using AJAX. The whole page reloads after the for data is submitted. Please help me with this. If there is any way to clear form data after submiting it, so that after refreshing the page no data is added to database do reply to this question.
After inserting the data, do a redirect:
header('Location:'.$_SERVER['PHP_SELF']);
After redirecting, refreshing won't cause data to be inserted again.
To show the message to the user I would simply set a flag via $_GET
. For example:
// Redirect and set $_GET variable
header('Location:'.$_SERVER['PHP_SELF'].'?showmsg=true');
To show the hidden div you could make a function:
function show_confirmation()
{
return isset($_GET['showmsg']) && $_GET['showmsg'] == 'true';
}
And use the function like this:
<div style="display:<?php echo show_confirmation() ? 'block' : 'none'; ?>">
<!-- Message for user -->
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With