You should reverse the order.
On submit:
- Process yours submit form.
- Push desired output message into yours session.
- Redirect to whatever/message page.
On message page show:
- Retrive message, pushed to session.
- Cleanup session record.
- Display message.
It's can be separate page, same page, as with submit for, or any other page.
Or...
Do the work with JavaScript and AJAX:
<?php
if(isset($_POST['submit'])) {
...
if (/all is ok/)
die(json_encode(array('status' => 'ok', 'message' => 'Hi!')));
else {
die(json_encode(array('status' => 'err', 'message' => 'I\'m failed!')));
}
}
?>
<form action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST" name="edit" >
<button type="submit" value="submit" name="submit">edit</button>
</form>
<script language="javascript">
$('form').submit(function() {
var parameters = ...; // collect parameters from form
$.getJSON('/url-to-script', parameters)
.success(function(response) {
if (response.message == "ok")
alert(response.message);
else
alert('Can\'t process input:
' + response.message);
})
.error(function(response) {
alert('What a terrible failure!');
});
});
</script>
When .success() fired - you can show supplied message to user via alert/custom modal message box an then make redirect (document.location = '<?php echo ... ?>'
) or replace form on page with some custom message and link/button to proceed... Lots of variants.