Solved

Send PHP variables through multi page form

Posted on 2010-08-27
8
1,200 Views
Last Modified: 2012-06-21
I am creating a small customer portal to capture invoice information.  I have created 4 pages for the user to walk through.
1. customer information
2. invoice information
3. desired sending method
4. confirm information and send

i would like for the data from each page to be carried throughout the system until the end.  I am currently pulling the information from page 1 to page 2 using a PHP variable and hidden form elements on page 2.  Then passing those hidden form elements to page 3 and so on.

Is that the best practice for passing the data from page to page or should i work some session variables?  If so, can someone give me some guidance on how to setup session variables and the capabilities of session variables.  thanks in advance.
0
Comment
Question by:axessJosh
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:honestman31
ID: 33542664
0
 
LVL 2

Accepted Solution

by:
morleys earned 500 total points
ID: 33542679
Storing this information in the session is the easiest way to manage data through a series of pages.
Early in your script (before you output anything) call: session_start();
You can then store and retrieve data using the the session array:
       $_SESSION['views'] = 1;
Generally you'll have a block at the start of the code which extracts data from the session into local variables with a usefull default
       $viewCnt = ISSET($_SESSION['views']) ? (int)$_SESSION['views'] : 0
If you have the same set of variables you will want to put that into a common subroutine.
On exit update the session with the new values
      $_SESSION['views'] = $viewCnt
0
 
LVL 2

Author Comment

by:axessJosh
ID: 33542719
I know just enough about PHP to be dangerous, but does the Session variables automatically get passed from page to page based on the session_start(); code?  What tells the second page that the session is still active?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:honestman31
ID: 33542784
but does the Session variables automatically get passed from page to page based on the session_start()  -->YES

hat tells the second page that the session is still active --> session_start()
0
 
LVL 2

Expert Comment

by:Tekati68
ID: 33542914
An easier way for you to do this that would not rely on cookies which the user can have turned off is to simply setup hidden form variables on each new page.

For example lets say on customer info form you get name, address, phone then on invoice information form simply setup hidden fields with the values from form 1.  You can name them the same except just hidden and at the end when you confirm information and send it will simple send all the fields.

This works if they hit the back button as well but has the added benefit that if they have cookies turned off it will still work!
0
 
LVL 2

Expert Comment

by:morleys
ID: 33543636
The session information is stored on the web server. A cookies is added to the response headers which provides the identity of the session and when returned from the client on the POST is used to reference the correct session data.

One advantage of session information is that you can store data that you don't want to send to and from the client so as to reduce the ability to hack the application.

Sessions do require that the client browser support cookies and its often a good idea to verify that in an early page of the site with a suitable warning that the site requires cookies.
0
 
LVL 2

Author Comment

by:axessJosh
ID: 33555307
so then that presents a new question,  which of the options would be the best and most effecient, session variables with its need for cookies to be enabled or hidden input fields variables?
0
 
LVL 2

Expert Comment

by:morleys
ID: 33557518
Depends on your needs and the audience you are addressing. I have usually found that most people keep cookies turned on and the use of the session gives you lot of flexibility to store information securely. If you put the information into hidden fields you expose that data to your users and permit them to manipulate it. Alternatively the use of hidden fields allows you to support non-cookie users, does not require your users to respond in a fixed length of time (the session will generally have a small timeout period). You have to balance the various attributes of the methods against the needs of your application and the environment you will be operating in. Personally, I usually go for sessions unless there is some prevailing need not to.  
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question