xtopolis Posted July 1, 2008 Share Posted July 1, 2008 Hi, In order to keep a form from being resubmitted by pressing refresh, I tend to post the form, extract/manipulate the post vars, and then use a header redirect back to the same page in order to clear the post stuff and basically start with a 'fresh' version of the form. My question is: I would like to use this method, but also find a way to return an error/success message. This is possible using $_GET and attaching things to the url, but IMO that is rather messy, and I would like to avoid it. Are there alternatives to this to accomplish what I want? Sample code of what I currently do: <?php if(isset($_POST['name'])) { //do something with the form vals Header('Location: ' . $_SERVER['PHP_SELF']); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="name" /><input type="submit" value="Process" /> </form> Basically if I was inserting into a database, I would like it to have a message saying if it succeeded or failed, while still having the form not being able to just be resubmitted. (Even if I don't allow it to go through[dupes], I still want it to be handled this way). Link to comment https://forums.phpfreaks.com/topic/112823-solved-header-redirect-successerror-message/ Share on other sites More sharing options...
revraz Posted July 1, 2008 Share Posted July 1, 2008 Use a session to set a flag and then read it when you load the page. Link to comment https://forums.phpfreaks.com/topic/112823-solved-header-redirect-successerror-message/#findComment-579478 Share on other sites More sharing options...
xtopolis Posted July 1, 2008 Author Share Posted July 1, 2008 Hmm, sounds like a good idea actually thanks. I'm not used to abusing session vars Nice one, thanks. Link to comment https://forums.phpfreaks.com/topic/112823-solved-header-redirect-successerror-message/#findComment-579492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.