Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send PHP variables through multi page form

Posted on 2010-08-27
8
Medium Priority
?
1,207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:honestman31
ID: 33542664
0
 
LVL 2

Accepted Solution

by:
morleys earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

688 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