Passing data through pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    Passing data through pages

    Hi,

    Part of one of my current projects is to provide an application form. This form needs to get quite a bit of data, so rather than have one really long form on one page I have split the data over 3 pages. Each page validates the input as you go so that the final page can submit it all to the database knowing that it is valid.

    What I don't know how to do is pass the data through the three pages. Each page needs to pass it's data onto the next page so that by the time the final page is complete all the data can be sent to the server.

    So each page has a form on it using method="post" and action that takes it to the next step of the process. Is there are a way to keep passing the increasing amount of data down the chain? I figure I could write to the database every time but I was hoping to avoid that so that if the process s aborted I don't have to worry about it.

    Does that all make sense? In short how can I pass data through 3 pages and onto the server?

    Many thanks
    Nathan
  • NoComment
    New Member
    • Jun 2007
    • 16

    #2
    Originally posted by nathj
    Hi,

    Part of one of my current projects is to provide an application form. This form needs to get quite a bit of data, so rather than have one really long form on one page I have split the data over 3 pages. Each page validates the input as you go so that the final page can submit it all to the database knowing that it is valid.

    What I don't know how to do is pass the data through the three pages. Each page needs to pass it's data onto the next page so that by the time the final page is complete all the data can be sent to the server.

    So each page has a form on it using method="post" and action that takes it to the next step of the process. Is there are a way to keep passing the increasing amount of data down the chain? I figure I could write to the database every time but I was hoping to avoid that so that if the process s aborted I don't have to worry about it.

    Does that all make sense? In short how can I pass data through 3 pages and onto the server?

    Many thanks
    Nathan
    Hi

    Reading just the first lines, my first solution was to simply write the results of each page to the database. But you said you don't want to do that.

    Another solution would be to pass them on to the next page via POST or GET. You could use hidden variables in your forms (like <input type="hidden" name ="password-from-page-1" value="previous ly-entered-password">), but this approach is not very professional, IMHO, since you have an increasingly bigger form with each page.

    You could do the following: write the user input of each page to the database. if the user aborts, just delete the data you already wrote to the database. And everytime a new user starts filling out your form, you could first check if the previous user aborted and if so, check if the previous input has already been deleted. If not, delete it then. This should keep the database clean.

    Yet, if you don't want to use a database for that, the only solution would be to use POST or GET due to the stateless nature of HTTP (which means there is no such inherent mechanism in HTTP that allows tracking of users or data).

    I hope this helps you somehow :)

    Kind regards.

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by NoComment
      Hi

      Reading just the first lines, my first solution was to simply write the results of each page to the database. But you said you don't want to do that.

      Another solution would be to pass them on to the next page via POST or GET. You could use hidden variables in your forms (like <input type="hidden" name ="password-from-page-1" value="previous ly-entered-password">), but this approach is not very professional, IMHO, since you have an increasingly bigger form with each page.

      You could do the following: write the user input of each page to the database. if the user aborts, just delete the data you already wrote to the database. And everytime a new user starts filling out your form, you could first check if the previous user aborted and if so, check if the previous input has already been deleted. If not, delete it then. This should keep the database clean.

      Yet, if you don't want to use a database for that, the only solution would be to use POST or GET due to the stateless nature of HTTP (which means there is no such inherent mechanism in HTTP that allows tracking of users or data).

      I hope this helps you somehow :)

      Kind regards.
      I think that writing to the DB at each stage will be the way I go, with some clever garbage collection routines it should be fairly safe. I guess that as I am starting this from scratch I have the chance to be really paranoid about data integrity and really anal about what goes to the DB and when.

      It does look like the best solution though.

      Thanks for the tip.
      nathj

      Comment

      • ronnil
        Recognized Expert New Member
        • Jun 2007
        • 134

        #4
        keep in mind that two or more users can fill out the form at the same time, so be sure to use session_id or the like to be sure it's the right data you extract in time of posting.

        Another way to do this, is to use hidden divs with your form, and on nextpress you can validate the form, if it's valid you hide it and show the next form.

        this safes some trafic and waiting time between form steps.

        You can also create the divs dynamically with javascript as you go along, this is great if you want to have different data depending on some of the form field's values.

        the great thing about this solution is that you don't have to worry about unsubmitted data, etc.

        the backdraw is ofcourse these 5% who don't have javascript activated....

        I always say, if you can avoid a task (like cleaning up for previous users) then avoid it :)

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Nathan.

          You can store the data in $_SESSION. Just make sure you call session_start() at the beginning of each of your scripts.

          For more information:

          Comment

          • NoComment
            New Member
            • Jun 2007
            • 16

            #6
            Originally posted by pbmods
            Heya, Nathan.

            You can store the data in $_SESSION. Just make sure you call session_start() at the beginning of each of your scripts.

            For more information:
            http://php.net/manual/en/ref.session.php
            You are right, it's a solution that didn't come to my mind. And even when cookies are disabled, the session ID is transferred by a GET parameter, right?

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, NoComment.

              Originally posted by NoComment
              And even when cookies are disabled, the session ID is transferred by a GET parameter, right?
              Yup yup.

              Comment

              • nathj
                Recognized Expert Contributor
                • May 2007
                • 937

                #8
                Looks like its going to be making use of $_SESSION.

                As for form validation, the next button isn't actually available until the form is 100% valid. I validate the data as the users enters it. I would show you this but the form is currently part of a site that is local only.

                I have bookmarked this page me to try out the ideas tomorrow.

                Thanks for all your help, if I get stuck I'll give a shout.

                Cheers
                Nathan

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  Heya, nath.

                  Glad to hear you got it working.

                  Good luck with your project, and if you ever need anything, post back anytime!

                  Comment

                  • shailpatel83
                    New Member
                    • Feb 2010
                    • 2

                    #10
                    Here is the good article that explains hows you can pass data between web pages.

                    [URLs DELETED]

                    Comment

                    • RedSon
                      Recognized Expert Expert
                      • Jan 2007
                      • 4980

                      #11
                      Instead of linking to posts on your blog, why don't you contribute to this community by posting relevant information here. After you post actual content you can link back to your blog for more information.

                      Comment

                      Working...