Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2004
    Posts
    194
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Pass Form Data Using $_SESSION?

    I'm having a bit of trouble with a script I'm working on. The idea is my order.php page by default will display a form for the user to fill in their details and what equipment they want to order. There is ten possibly types of equipment for them to order, if they select say types 2, 5, and 9 then they need to fill in more info as there are individual forms to go with those orders. So the idea is that on submission of the form they are presented with another form, generated by the same order.php file, which they fill in, and are then presented with the next needed form etc. This isn't a prob, i've got this all pretty much working, the problem i'm having is that i'm passing the form data using hidden fields that have the values as <?php echo $_POST['name']; ?> when the form is submitted, this works fine, however when the page has loaded again the values that were originally entered are lost.

    The idea is i need to be able to successfull carry over all submitted data over a possible seven forms/pages until the data is compiled in an email and sent off. I read that this data can be easily stored and carried over with sessions but i haven't been able to find any info on how to do this. Either that or is there a better/easier way of passing the data more easily?

    Cheers in advance.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well you could use sessions. You could just set all needed fields in the $_SESSION array and viola.

    You could use Hidden fields...

    Or you could store the temporary data in a DB or a file.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    194
    Thanks
    5
    Thanked 0 Times in 0 Posts
    How do you store them in the $_SESSION array?

    Currently I have code along the lines of:

    Code:
    <?php
    
    session_start(); 
    
    $_SESSION["qtylaptop"] = $_POST['qtylaptop'];
    $_SESSION["qtyprinter"] = $_POST['qtyprinter'];
    $_SESSION["qtymobile"] = $_POST['qtymobile'];
    $_SESSION["qtypager"] = $_POST['qtypager'];
    $_SESSION["qtyusbkey"] = $_POST['qtyusbkey'];
    
    if (!empty($_SESSION['qtylaptop']) && ($_SESSION['laptopdone'] != "true")) {
    	//display form for laptop
    	$_SESSION['laptopdone'] = "true";
    
    } else if (!empty($_SESSION['qtyprinter']) && ($_SESSION['printerdone'] != "true")) {
    	//display form for printer
    	$_SESSION['printerdone'] = "true";
    
    } else if (!empty($_SESSION['qtyusbkey']) && ($_SESSION['usbkeydone'] != "true")) {
    	//display form for usb key
    	$_SESSION['usbkeydone'] = "true";
    
    } else {
    	//display summary of order/confirmation page
    }
    After submission i get the laptop page (provided it has been ordered that is), but after that I just get a blank page when the laptop form is submitted so i dont think the data is being passed.

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The way you're setting the $_SESSION vars seems fine. What happens if you echo the $_SESSION variables right after you call them, do they return any values?

  • #5
    Regular Coder
    Join Date
    Jun 2004
    Posts
    194
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I just tested this by entering data into the two of the fields that should return an extra form. After the default form was submitted and the first form returned, the value for the second value was successfully echoed. After submitting that form though the value was lost. This is the code i used to test it:

    Code:
    if (!$_SESSION['qtypager']) {
    	echo "The session data hasn't been passed";
    } else {
    	echo $_SESSION['qtypager'];
    }
    In the default form i entered the values for the fields qtylaptop and qtypager. They seem to be lost after one page reload.

    EDIT: Just ran phpinfo(); this is what i says about sessions:

    session.auto_start Off Off
    session.bug_compat_42 Off Off
    session.bug_compat_warn On On
    session.cache_expire 180 180
    session.cache_limiter nocache nocache
    session.cookie_domain no value no value
    session.cookie_lifetime 0 0
    session.cookie_path / /
    session.cookie_secure Off Off
    session.entropy_file no value no value
    session.entropy_length 0 0
    session.gc_divisor 1000 1000
    session.gc_maxlifetime 1440 1440
    session.gc_probability 1 1
    session.name PHPSESSID PHPSESSID
    session.referer_check no value no value
    session.save_handler files files
    session.save_path no value no value
    session.serialize_handler php php
    session.use_cookies On On
    session.use_only_cookies Off Off
    session.use_trans_sid Off Off
    Last edited by Acid; 02-08-2005 at 05:10 PM.

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Posts
    194
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ahh nevermind, figured it out now. Thanks to all who replied and cheers to brandon for the help in solving this.


  •  

    Posting Permissions

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