ryy705 Posted June 25, 2009 Share Posted June 25, 2009 hello, I am building a simple car enthusiast site. I would like to allow users to add as many cars to their profile as they would like. The easiest way to do this would be to create a form to takes in car info and posts back to itself, allowing the user to enter info about another car. However, this process will get completely screwed up if the user hits the back button. That will create duplicate entries. How do you guys build forms like this? Many thanks in advance. Link to comment https://forums.phpfreaks.com/topic/163667-form-design-question/ Share on other sites More sharing options...
phant0m Posted June 25, 2009 Share Posted June 25, 2009 Well, you can use sessions and store some hash to validate the form submission. That way you can detect an unintended submission. Or: use header('Location: someplace.php'); to force the browser to reload the page instantly Link to comment https://forums.phpfreaks.com/topic/163667-form-design-question/#findComment-863615 Share on other sites More sharing options...
Rayhan Muktader Posted June 25, 2009 Share Posted June 25, 2009 When you "use a hash" do mean to say that I should use a form key? I do not understand the part about reloading the page. How would that work? Could you kindly explain? Link to comment https://forums.phpfreaks.com/topic/163667-form-design-question/#findComment-863629 Share on other sites More sharing options...
947740 Posted June 25, 2009 Share Posted June 25, 2009 Wait...are you the same person? Link to comment https://forums.phpfreaks.com/topic/163667-form-design-question/#findComment-863633 Share on other sites More sharing options...
phant0m Posted June 25, 2009 Share Posted June 25, 2009 As for the reloading part: header('Location: http://www.example.com/someplace.php'); This sends a header, which forces the browser to load the URL specified in the header. Your browser will *not* create a new entry in your browsing history("back button" in your browser) When the page is reloaded, it is requested with GET, previous POST data is discarded. :arrow: when your visitor visits another page on your site, and then hits the "back-button", the form is not sent again. As for using a hash: I do not understand what you mean with a "form key", but here's what I thought: you generate a hash(e.g. with md5(time()) and store it in the session. Insert this hash into your form using a hidden field. When you process the form, fetch the hash from $_POST and compare it with the one in your session variable. If they are equal, continue and enter your info into the database or whatever. After that, remove the hash from your session. Link to comment https://forums.phpfreaks.com/topic/163667-form-design-question/#findComment-863636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.