How do I keep from reprocessing forms?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Thomas

    How do I keep from reprocessing forms?

    This is my problem.

    I want to submit a form to another page to process the data from said form.
    Then the person can go on to another part of the site or another site
    altogether. However If the person later clicks the <back button> enough
    times they will arrive back at the page that processed the data the first
    time and the same data will be processed again. How can I prevent this?
    My first thought was to use a cookie and set it on submit of the form but I
    have not been able to get that to work. Any suggestions?


    -Alex


  • Jenkins

    #2
    Re: How do I keep from reprocessing forms?

    I'm just getting into this, but I understand the following should work:

    calling page:
    ....
    <form method="POST" action="page2.p hp">
    ....
    <input type="text" name="searchtex t" size="50">
    <input type="submit" value="search">
    </form>
    ....

    Page you don't want to reprocess (page2.php):
    ....
    $searchtext = $_POST[searchtext];
    if (isset($searcht ext))
    {
    unset ($searchtest);
    ... do everything else...
    }



    "Alex Thomas" <alex.thomas@mi ndspring.com> wrote in message
    news:piYmb.4270 $X22.1425@newsr ead2.news.atl.e arthlink.net...[color=blue]
    > This is my problem.
    >
    > I want to submit a form to another page to process the data from said[/color]
    form.[color=blue]
    > Then the person can go on to another part of the site or another site
    > altogether. However If the person later clicks the <back button> enough
    > times they will arrive back at the page that processed the data the first
    > time and the same data will be processed again. How can I prevent this?
    > My first thought was to use a cookie and set it on submit of the form but[/color]
    I[color=blue]
    > have not been able to get that to work. Any suggestions?
    >
    >
    > -Alex
    >
    >[/color]


    Comment

    • Tom Thackrey

      #3
      Re: How do I keep from reprocessing forms?


      On 26-Oct-2003, "Jenkins" <news@djenkins. nu> wrote:
      [color=blue]
      >
      > "Alex Thomas" <alex.thomas@mi ndspring.com> wrote in message
      > news:piYmb.4270 $X22.1425@newsr ead2.news.atl.e arthlink.net...[color=green]
      > > This is my problem.
      > >
      > > I want to submit a form to another page to process the data from said[/color]
      > form.[color=green]
      > > Then the person can go on to another part of the site or another site
      > > altogether. However If the person later clicks the <back button>
      > > enough
      > > times they will arrive back at the page that processed the data the
      > > first
      > > time and the same data will be processed again. How can I prevent
      > > this?
      > > My first thought was to use a cookie and set it on submit of the form
      > > but[/color]
      > I[color=green]
      > > have not been able to get that to work. Any suggestions?
      > >[/color]
      > I'm just getting into this, but I understand the following should work:
      >
      > calling page:
      > ...
      > <form method="POST" action="page2.p hp">
      > ...
      > <input type="text" name="searchtex t" size="50">
      > <input type="submit" value="search">
      > </form>
      > ...
      >
      > Page you don't want to reprocess (page2.php):
      > ...
      > $searchtext = $_POST[searchtext];
      > if (isset($searcht ext))
      > {
      > unset ($searchtest);
      > ... do everything else...
      > }
      >
      >[/color]
      Sorry, this won't work because reprocessing page2.php will repost the form
      fields.

      AFAIK the only way to avoid the refresh/back problem is to use a session
      variable to keep track of what's been posted and refuse the repost.


      --
      Tom Thackrey

      tom (at) creative (dash) light (dot) com
      do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

      Comment

      • Steve

        #4
        Re: How do I keep from reprocessing forms?

        One possibility would be to check if this user has posted data already
        and ignore it if he/she has.
        This is simple if you are taking form data and placing it inside of a
        database. Not so simple if something else is being done... i.e. An
        customer service email script.
        I have a site, where users can purchase items. To do so they have to
        fill in a signup form. Obivously we only want each user to have one
        account, but double clicking submit would normally create a new
        account for them, so here is what I do.

        I check the "critical information" against the database, if it exists
        I just ignore the input. It looks something like this.

        $critical_info = $_POST['email'];

        $query = "SELECT * from mytable WHERE email ='$critical_inf o'";
        $result = mysql_query($qu ery);

        if(!$result){
        //Do whatever it is I need to do to sign this customer up

        }else{
        echo <<< EOF
        Sorry but it appears you've already signed up!<br>
        <a href= "mysite.com/lostpass.php">C lick here to retrieve your
        password</a><br>
        EOF;
        }

        So basically, if you are storing the information, just check to see if
        you already have the information before accepting it. If yes ignore,
        otherwise store.

        I hope this helps.

        "Alex Thomas" <alex.thomas@mi ndspring.com> wrote in message news:<piYmb.427 0$X22.1425@news read2.news.atl. earthlink.net>. ..[color=blue]
        > This is my problem.
        >
        > I want to submit a form to another page to process the data from said form.
        > Then the person can go on to another part of the site or another site
        > altogether. However If the person later clicks the <back button> enough
        > times they will arrive back at the page that processed the data the first
        > time and the same data will be processed again. How can I prevent this?
        > My first thought was to use a cookie and set it on submit of the form but I
        > have not been able to get that to work. Any suggestions?
        >
        >
        > -Alex[/color]

        Comment

        Working...