Jump to content

Form design question


ryy705

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.