I’m using this code:
if(isset($_POST['btitle'])) {
if(count($errors) > 0) {
foreach($errors as $error)
$errContent .= "<li>".$error;
echo notification(
$errContent,
FALSE,
"The following errors were encountered:"
) . "<div style='margin-bottom: 10px;'></div>";
}
else {
echo notification(
"<li>New form added!",
TRUE,
"Success:"
) . "<div style='margin-bottom: 10px;'></div>";
}
}
When I type something in the input named ‘btitle’ and hit the submit button, everything is fine, until I refresh the page – it should loose the data and start again after refreshing, but it keep saying “Success:” even if the ‘btitle’ input is empty.
What am I doing wrong?
you need to redirect the user to the same page and loose the post data.
now, in the same page (file.php) you need to:
BTW, if you don’t do it, the entire submitting form will be act again like you resubmit it.
for instance, if you insert data to the database, it will be insert over and over again when you refresh the page, so if you redirect as suggested, you loose the posted data and now you can show the errors or success.