loren646 Posted February 20, 2013 Share Posted February 20, 2013 i searched on google and can't seem to come up with an answer. I keep getting linked to some wiki article about cookies or something. Is there a way to disable the button after submit. or force user to click an "edit" button to enable "update" button? The website is below. Basically you enter the available apartment (select landlord, building, enter price, apt #, # of bedrooms). Hit enter. Added to database. http://responsiblyvodka.com/tester.php if you hit refresh it either reenters it or enters a blank line. Quote Link to comment Share on other sites More sharing options...
loren646 Posted February 20, 2013 Author Share Posted February 20, 2013 Solution? When user clicks submit button they are taken to page tester2.php which is a copy of tester1.php. and when user updates on tester2.php it goes to tester1.php. This solves some of the problem but not refresh.... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2013 Share Posted February 20, 2013 Please don't do that. You should never have code copied on multiple pages. You have a few options for solving this problem. A. Have your form on one page, and the processing for the form on a second page. When you submit the form, go to the processing page to handle it. Then use a header redirect to send the user back to the form page or a third confirmation page to display any errors or success messages. They can then refresh the page all they want, it won't hurt anything. B. Keep everything on one page, but instead of simply displaying after the processing, use the same header redirect back to the same page. Either way, you need to store your messages in the SESSION then send the user to some kind of confirmation page when you're done, using a redirect, so they cannot use refresh to resubmit the form. Quote Link to comment Share on other sites More sharing options...
loren646 Posted February 21, 2013 Author Share Posted February 21, 2013 thanks for the suggestion jessica. i couldnt get your way to work but i tried another method and I've solved half of it. I allowed the user to select but if all the boxes are NOT filled than when they click to update. nothing happens. if (isset($variable, $variable)) { query } my problem now is if they updated and then hit refresh then it resubmits previous data. but if they click the button and hit refresh - no problem. So either I make the page click the button automatically on reload (if possible) or i have last inserted data matched with current data if the same do nothing. Quote Link to comment Share on other sites More sharing options...
loren646 Posted February 21, 2013 Author Share Posted February 21, 2013 Solved. at the top of my forum <?php $close = 0; at the place where i insert the data into mysql If ($close < 1) { if (isset($variable, $variable)) { query } $close=1; } Quote Link to comment Share on other sites More sharing options...
Christian F. Posted February 21, 2013 Share Posted February 21, 2013 The correct way to solve this is method B as posted by Jessica. Use a header ("Location: ") call to redirect to the current page, after you've successfully processed the submitted data. This will then cause the browser to perform a new (GET) request for the page, and forgetting about the POST request. End result: F5 refreshes, not re-submits. Quote Link to comment Share on other sites More sharing options...
loren646 Posted February 22, 2013 Author Share Posted February 22, 2013 thanks christian and jessica. i've decided on the second processing page and using the header. it's much cleaner. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.