I'm using a simple form (from www.csskarma.com/lab/contactForm/) which processes on the page, and then throws up a success or failure message.
My question is two fold (and probably dumb):
1) after submission the page url changes from "/" to "/index.php" -- which isn't a problem, but if you try to reload you get the "this will resubmit everything" message. Is there a way to get around this? I don't mind the url change but the resubmit on reload is kind of problematic.
2) It would be great to have the form load again, empty. In case, someone wanted to...write twice? This would be less of a problem if reloading showed a clean form, so, I guess it's almost one or the other.
Everything is being processed by validate.js which is enormous and which I can't begin to comprehend.
Any help greatly appreciated.
redirect to some location, will stop this happening
redirect to the form page
header('Location: http://www.example.com/form.php');
Utilising AJAX to submit the form with the jQuery Form Plugin means you could do away with any refreshes and keep your URL clean.
I have revised the PHP, hopefully it will address both of your issues:
This goes right after the opening php tag
// get the status from the url bar
$status = $_GET['status'];
Revised success message:
if ($success){
// we want to redirect via PHP so that users do not get that "resubmit message"
header('location: '.$_SERVER['PHP_SELF'].'?status=sent');
} else {
// we want the form to show up again? so, pass an error
$status = 'error';
}
This goes right before the closing "?>" tag:
# run the status through a switch if not empty
if(!empty($status)) {
switch($status) {
case 'sent':
echo('<p class="feedback yay">All is well, your e–mail has been sent.</p>');
break;
case 'error':
echo('<p class="feedback oops">Something went wicked wrong; maybe you clicked too hard.</p>');
break;
}
}
Thanks, all.
I ended up keeping the form out of the php declaration (it had been inside final tags) and, while re-submit on reload is still an issue, everything seems a lot cleaner with the form still shown along with the thankyou message. Works for now, anyway. Thanks again, --m