1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to save before submit the form

Discussion in 'PHP' started by vetrivel, Jul 9, 2009.

  1. #1
    Hi Guys,
    I am having a form with nearly 20 fields.
    some people only fills few details and navigate to previous page and once he arrived back they lost all the data they typed.How to store this ?
    what are the methods available to do this.
    But once they submitted all the details get cleared.

    Please advice me.
     
    vetrivel, Jul 9, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can save their details in a session or a cookie and then echo them out.

    For example (with sessions), on the form handler script:

    
    session_start(); //This must be the first line for a session to work
    
    //Assign submtited post variables to session variables, which can be transferred from page to page
    $_SESSION['formName'] = $_POST['name'];
    $_SESSION['formAge'] = $_POST['age'];
    $_SESSION['formGender'] = $_POST['gender'];
    //etc for the 20 post variables
    
    PHP:
    Then on your form page:

    
    session_start(); //Again this needs to be the first line
    //Doctype
    <html>
    <head>
    ///Head
    </head>
    <body>
    <form action="handler.php" method="post">
    <input type="text" name="name" value="<?php echo $_SESSION['formName'] ?>" />
    <input type="text" name="age" value="<?php echo $_SESSION['formAge'] ?>" />
    <input type="text" name="gender" value="<?php echo $_SESSION['formGender'] ?>" />
    </form>
    </body></html>
    
    PHP:
     
    wd_2k6, Jul 9, 2009 IP
    Bohra likes this.
  3. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wd_2k6, I think your solution will not work, because on a back hit, the form is not posted yet and the post array will still be empty and therefore the session array will also be empty.
    My approach would be to write some ajax (javascript) to store the values of the fields to the session array on field exit, the session array will be filled accordingly then would be displayed the way Wd_2k6 explained.
     
    zeronese, Jul 9, 2009 IP
  4. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I m using the Jquery .Is that helps in anyway?

     
    vetrivel, Jul 9, 2009 IP
  5. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, it helps.
    Maybe you’ll have to research this further depending on what kind of fields you have on your form. Let me try to give you a hand, but you have to clean it to fit your needs.
    Example:
    If you have a text field named mytextfield, you can write the ajax using jquery code to update the $_session[‘mytextfield’] value every time your user types in a character.
    I know it is easier said than done, but at least you can start somewhere.

    Best luck :)
     
    zeronese, Jul 9, 2009 IP
  6. anthonywebs

    anthonywebs Banned

    Messages:
    657
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ajax would work here
     
    anthonywebs, Jul 9, 2009 IP
  7. mahi272

    mahi272 Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you can save your form by taking its screenshots and pasteing it on paint.It will take few seconds.If you have some doubts then keep on touch with me in DP ieill help you.
     
    mahi272, Jul 9, 2009 IP
  8. methomps

    methomps Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    lol wut?

    I don't think you understood the issue.
     
    methomps, Jul 9, 2009 IP
  9. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi ,
    I dont like to grab the page and save it .What i need is entirely differnent in from your answer.


     
    vetrivel, Jul 9, 2009 IP