Jump to content

data gets reposted/submitted with refresh... disable?


loren646

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.