Results 1 to 6 of 6

Thread: Form submit question

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Form submit question

    I've got a simple form on my page (name, email and how you found me) which works fine and writes the details to a txt file once the form has been submitted. However, I seem to be getting people you submit the form and then refresh the page (for whatever reason) and their details get added again to the txt file.

    My question is: Is there a way to check if a person refreshes the screen and if they have bypass the writing to the txt file routine?

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Form submit question

    There is a way to prevent it from happening in the first place. Have the form submit to a processing page an send a redirect header after processing.

    As for checking you could open the text file and look for the the appropriate name / email combination but that would be an intensive process.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Form submit question

    Using a database is out of the question?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Form submit question

    Whether you use a database or not you will still have the problem of lingering POST data unless you use a 303 redirect from your POST handler page.
    PHP Code:
    header('HTTP/1.1 303 See Other');
    header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}"); 
    303 responses are not cacheable, so navigating backwards from the redirected response will function as expected.
    Last edited by penagate; Mar 16th, 2008 at 07:07 PM.

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Form submit question

    I never thought of using the redirect before. I've been using a SELECT query to see if the same "post" was saved by the same user/ip/email/message/etc.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Form submit question

    You should use a composite primary key for that. That will save you one query per post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width