SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 54
  1. #1
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hitting the back button

    Hi there
    I have a 3 page registration form where users input their information like name address etc... on page 4 of the registration, it's basically a confirmation page that brings up everything they've entered and asks them to double check...

    I have a back button at the bottom of the page in case they want to go back and update anything they might have entered wrong or mispelled but when you hit the back button, all the information is wiped out...

    Is there anyway to have that information be there when they hit the back button to page 3, 2 or 1?

    Thanks

  2. #2
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Store all their data as an array in a session variable or in a database and have the form elements populated accordingly.

  3. #3
    SitePoint Enthusiast ssx-gun's Avatar
    Join Date
    Sep 2002
    Location
    Strongsville, OH
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could store information in cookies or sessions.
    PHP: Pills Help People
    ---
    weird-one.com


  4. #4
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like the sound of the session variable... would that basically mean that the data wouldn't be inputed right away... it would be input once they hit the "submit" button after the confirmation page?

    Where is the data stored in a session variable? hopefully not in "hidden" fields...

    Thanks...

  5. #5
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    session variables are stored as a text file on the server..

    a cookie is placed on teh client with a session id

    eg .

    s98dfasd8f9823h23jh239889hd338bn

    this willl match with the servers session id. and will be able to retrieve the data.

    Make sure you use session_start() after your first<? tags so that the server knows you need the session file..

    also you'll need to do use ini_alter() to change the cookie lifetime, otherwise as soon as they change the page, the temp file on the server will be deleted.
    Kreative Development
    Infinite Possibilities

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by briancastellanos

    also you'll need to do use ini_alter() to change the cookie lifetime, otherwise as soon as they change the page, the temp file on the server will be deleted.

    thats not true.

  7. #7
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right...you can also specify cookie lifetime in php.ini..
    Kreative Development
    Infinite Possibilities

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. There is absolutely no need to set the lifetime of the session/cookie if you use "session_start();" at the beginning of each page that relies on session vars.
    Current Project: Winamp - Online Remote

  9. #9
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok... I think I'm getting it...

    So how do I create the cookie? Or is it automatically created when I use the "session start"

  10. #10
    SitePoint Addict greg76's Avatar
    Join Date
    Aug 2004
    Location
    Los Feliz, CA
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    session_start
    ();

    $_SESSION['name'] = $_POST['name'];
    $_SESSION['phone'] = $_POST['phone'];
    .
    .
    .
    and 
    so on on each page
    ?>
    and you need to define a value to each field of your form(s), eg:
    Code:
    <input name="first" type="text" class="form1" id="first" tabindex="1" value="<? if (isset($_SESSION['first'])) echo $_SESSION['first'];?>">
    Cheers,
    Gee

  11. #11
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you don't change the cookie lifetime of the session though, when the user closes the browser, the session will be over, and the session data destroyed. This means if you log in, do your stuff, close your broswer, then come back, you'll have to login again..good if your like doing sensitive info, but like forums, you're likely to open and close your browser several times....ill leave you to your own devices.
    Kreative Development
    Infinite Possibilities

  12. #12
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brian
    That's a good thing... because technically, the user would register in 1 "session"... meaning that there is no save feature that would allow the user to save half way through... If he leaves the browser, that means he doesn't want to register or he's finished registering...

    Greg76
    Thanks for that method... I'll give it a try... so that will "store" the inputs for the browser's session right? I want to make sure since it might take me a while to code?!

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Losse is right. If you want to allow the user to stay logged in after the browser closes, do so with a separate, dedicated cookie. Don't do it with sessions
    Current Project: Winamp - Online Remote

  14. #14
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One last question...

    On page 1 of the registration form I have an INSERT quiery to input the data in the DB
    On page 2 I have an UPDATE for the remaining fields
    On page 3 I also have an UPDATE statement

    On page 4 it's the confirm page to make sure the data is right for the user.

    My question is, if the user were to go back to page 1 and make some changes, would that basically create an issue since there is an "INSERT" quiery and not an "UPDATE" quiery?

    Because basically, once the user clicks on "next" to go to page 2, the user ID is already created and for those fields, the INSERT quiery inputs the data...

    Wouldn't a second INSERT create an additional user ID?

    thanks

  15. #15
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For simplicity sake - I'd simply throw it all into the database as you go - and simply have a field like - "Active = 'No'"; until the form is completely filled out.

    If you don't know much about SESSIONS and COOKIES you might be a while.

    Either way - they are all methods of data storage - but from a beginner standpoint I think the database would be the easiest route.

  16. #16
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks HiFi...

    What would be your suggestion with Sessions? I think that we ruled out the coookie option...

  17. #17
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simply insert ur query in db on 1st page and keep last inserted id in session['lastid'] then goto 2nd and so on , while returninig back to page 1
    just check if session['lastid'] != "" then instead of insert just fire the update query.

  18. #18
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you delay the database writing until the last page. That way you won't get an inconsistent database state, due to uncompleted forms.

  19. #19
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Can't you delay the database writing until the last page. That way you won't get an inconsistent database state, due to uncompleted forms.
    In this case he needs to maintain the variable values indefinitely on every page which is a tedious job to do, so I think storing in db and donít bother about the data between intermediate pages.
    But in case of delay one advantage is that if user left the registration after 3rd page or u can say b 4 confirmation page then that db stat remains as it is.
    So either u can store in DB or u can delay till last page. But if ur storing it in DB then make sure if registration is not complete then take care of some related action on unwanted data in DB.

  20. #20
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's a way to delay the writing of the info to the database? Can it be done in a session? ie- store the data in a session and INSERT from the confirmation page ??

    How are these things done "usually?"

  21. #21
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes delay in terms of session , u can say that , many people use db in this case and many use session or simple var.
    its all matter of hands.

  22. #22
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to use a session...

    Would this just be a matter of putting a SESSION START at the top of all the registration pages and like greg76 suggested a

    PHP Code:
    $_SESSION['name'] = $_POST['name']; 
    on all the pages for the fields?

    And then an INSERT on page 4 (the confirmation page)?

    Thanks for your help

  23. #23
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u can do the same , just write session_start() on every single page and insert on page4(the confirmation page)

  24. #24
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh! that simple?

    All I need is a session start?

    So I should remove any database quiery I have created right? For example right now on page 1 I have INSERT, page 2 and three I have UPDATE...

    So should I remove those and only have the session start?

  25. #25
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another question...

    On page 4 - the confirmation page, I bring up all the fields the user input in the first 3 pages with a SELECT quiery... Since there won't be anything in the DB to "SELECT" from, how would I display those fields on the confirmation page?


Bookmarks

Posting Permissions

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