Jump to content

Multipage form


jntcomputers

Recommended Posts

I have a four page form and want to store the data in a session until it is submitted. I have this code at the top:
[code]
session_start();
$_SESSION['id'] = uniqid();
if (isset($_POST[$key])) {
        $_SESSION[$key] = $_POST[$key];
        echo "TESTING SESION SET!<br>";
}
print_r ($_SESSION);
print_r ($_POST);
[/code]

But this out puts:
Array( [id] => 444e9b5b2d41c [] => ) Array ( [B_FirstName] => test [B_MiddleInitial] => [B_LastName] => [B_SSAN] => [B_DateOfBirth] => [B_Email] => [B_HomePhone] => [B_CellPhone] => [B_WorkPhone] => [B_MaritalStatus] => ---- [B_YearsSchool] => [B_NumDependents] => [B_DependentAges] => [B_HomeAddress1] => [B_HomeAddress2] => [B_HomeCity] => [B_HomeState] => [B_HomeZip] => [B_YearsAtAddress1] => [B_MailingAddress1] => [B_MailingAddress2] => [B_MailingCity] => [B_MailingState] => [B_MailingZip] => [B_PrevAddress1] => [B_PrevAddress2] => [B_PrevCity] => [B_PrevState] => [B_PrevZip] => [B_YearsAtAddress2] => [coborrower] => Next Page --> )

As you can see the session variables from the form are blank, but the post variables are not. What am I doing wrong?!?
Link to comment
Share on other sites

A simple method to force POST values into a session...

[code]<?php
if(!session_id()) session_start();

// makesure user got here using the form
if(!$_POST['Submit']){ // name of your submit button
    die ("You must have got here by mistake?");
}
// force post data to session for tracking

if(isset($_POST['Submit'])){ // name of your submit button
    foreach($_POST as $key => $value){
    $_SESSION['post_value'][$key] = $value;    
    }
}

echo "<pre>";
print_r($_SESSION);
echo "</pre>";
?>[/code]
Link to comment
Share on other sites

[!--quoteo(post=368662:date=Apr 25 2006, 06:14 PM:name=Ferenc)--][div class=\'quotetop\']QUOTE(Ferenc @ Apr 25 2006, 06:14 PM) [snapback]368662[/snapback][/div][div class=\'quotemain\'][!--quotec--]
$_SESSION['post_value'][$key] = $value;
[/quote]

Does this mean I have to enter the field value for every field.

I.E.
[code]
$_SESSION['name'][$key] = $value;
$_SESSION['email'][$key] = $value;
[/code]

And so on? Because there are liike 80 fields. Is there a way to do it dynamically?
Link to comment
Share on other sites

[!--quoteo(post=368691:date=Apr 25 2006, 07:52 PM:name=jntcomputers)--][div class=\'quotetop\']QUOTE(jntcomputers @ Apr 25 2006, 07:52 PM) [snapback]368691[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Does this mean I have to enter the field value for every field.

I.E.
[code]
$_SESSION['name'][$key] = $value;
$_SESSION['email'][$key] = $value;
[/code]

And so on? Because there are liike 80 fields. Is there a way to do it dynamically?
[/quote]


[b]$key will be the name of the input from the form[/b]. It will loop thruogh all the post data

I used ['post_value'] to seperate data in the session.
You can remove it if you like, makes no difference
what I posted will take all the data and put in the session dynamicly.

the session would look like this
[code]array(

    [post_data] => array(
    
            [email] => test
            
            [name] => test
            
        )
)[/code]

Link to comment
Share on other sites

Copy this to your server to see how it works if you like
[code]<?php
if(!session_id()) session_start();
$button_lable = "Next";
// force post data to session for tracking
if(isset($_POST['Submit'])){
    $button_lable = "Again?";
    foreach($_POST as $key => $value){
    $_SESSION['new'][$key] = $value;    
    }
    echo "<pre>";
    print_r($_SESSION);
    echo "</pre>";
}
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <p>
    <input name="name" type="text" id="name">
    name <br>
    <br>
    <input name="another field" type="text" id="another field">
  </p>
  <p>
    <input type="submit" name="Submit" value="<?php echo $button_lable ?>">
    <input name="hidden" type="hidden" value="foo">
  </p>
</form>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.