Jump to content

2 page webform passing variables


vavi2s

Recommended Posts

ok ive searched everywhere online for a webform that is in 2 or more parts... so the first page passes variables to the second page then saves info for next page to submit all info from both pages of application to a server etc.

 

 

ideally my page would look like this...

 

page 1:

 

small form with 3 fields:

 

1. type of loan:

[dropdown menu]

a. Cashout refinance

b. Purchase

 

2. Property type:

[dropdown menu]

a. single family

b. multi-unit, etc.

 

3. Property State:

[dropdown menu]

a. states.......

 

[Next Page] <---Button

 

page 2:

 

a few more fields:

 

(for example:)

1. Approximate credit score

[dropdown menu]

a. 650-700 etc....

 

2. Phone number

[textbox]

 

3. email address

[textbox]

 

[submit button]

 

 

I know its possible, i just need to be put on the path... any help is much appreciated!

 

 

 

Link to comment
Share on other sites

Because PHP does not pass on variables page to page. You can save the posted data into a session. So when you submit the first form to your second form save the posted data into a session, eg

$_SESSION['step1_data'] = $_POST;

After you have saved the posted data. Display your next form. On your final page you can work with the data you have collected. Here is an example

 

step1.php

<form action="step2.php" method="post">

    <p>
      Loan Type:
      <select name="loanType">
        <option>Loan Type 1</option>
        <option>Loan Type 2</option>
        <option>Loan Type 3</option>
      </select>
    </p>

    <p>
      Property Type:
      <select name="peopertyType">
        <option>Property Type 1</option>
        <option>Property Type 2</option>
        <option>Property Type 3</option>
      </select>
    </p>

    <p>
      Property State:
      <select name="peopertyState">
        <option>Property State 1</option>
        <option>Property State 2</option>
        <option>Property State 3</option>
      </select>
    </p>

    <p><input type="submit" name="step1_submit" value="Continue →" /></p>
</form>

 

step2.php

<?php
session_start();
if(isset($_POST['step1_submit']))
{
    $_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */
?>
<form action="step3.php" method="post">

    <p>
      Credit Score:
      <select name="creditScore">
        <option>500 - 600</option>
        <option>600 - 700</option>
        <option>800 - 900</option>
      </select>
    </p>

    <p>
      Phone Number: <input type="text" name="phoneNumber" />
    </p>

    <p>
      Email Address: <input type="text" name="emailAddress" />
    </p>

    <p><input type="submit" name="step2_submit" value="Continue →" /></p>
</form>
<?php
}
else
{
?>
Please fill in <a href="step1.php">Step 1</a>
<?php
};
?>

 

step3.php

<?php
session_start();

if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
{
    echo "Your data: <h1>Step 1</h1>";

    foreach($_SESSION['step1_data'] as $field => $value)
    {
        if($field != 'step1_submit')
            echo "<p><b>$field</b> = $value</p>";
    }

    echo "<h1>Step 2</h1>";

    foreach($_POST as $field => $value)
    {
        if($field != 'step2_submit')
            echo "<p><b>$field</b> = $value</p>";
    }
}
else
{
    echo 'Fill in <a href="step1.php">Step 1</a>';
}
?>

 

Link to comment
Share on other sites

i got this code from a tutorial online haha

 

<?php

//--------------------------Set these paramaters--------------------------

 

// Subject of email sent to you.

$subject = 'Results from Contact form';

 

// Your email address. This is where the form information will be sent.

$emailadd = 'mail@rdsnetworks.net';

 

// Where to redirect after form is processed.

$url = 'http://www.rdsnetworks.net/confirmation.html';

 

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.

$req = '0';

 

// --------------------------Do not edit below this line--------------------------

$text = "Results from form:\n\n";

$space = ' ';

$line = '

';

foreach ($_POST as $key => $value)

{

if ($req == '1')

{

if ($value == '')

{echo "$key is empty";die;}

}

$j = strlen($key);

if ($j >= 20)

{echo "Name of form element $key cannot be longer than 20 characters";die;}

$j = 20 - $j;

for ($i = 1; $i <= $j; $i++)

{$space .= ' ';}

$value = str_replace('\n', "$line", $value);

$conc = "{$key}:$space{$value}$line";

$text .= $conc;

$space = ' ';

}

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

?>

 

Link to comment
Share on other sites

thanks but im sure you can guess what my response is going to be...  HOW??  :)  I cant wait to be able to look at code like you guys and see whats wrong with it in a split second but for now I am the low man on the totem pole and need a boost.  can you explain where I would add the missing variables thanks again

Link to comment
Share on other sites

the 3rd page of code from wildteen does it, just change it to pass the data to the $text variable for your email instead

foreach($_SESSION['step1_data'] as $field => $value)   
{        
if($field != 'step1_submit')  echo "<p><b>$field</b> = $value</p>";  
  }

Link to comment
Share on other sites

in the process of learning it. having a tough time obviously but im sure everyone here was at my stage at some point, i just hope when I do get to that stage I can make the newbies feel as welcome as you guys have

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.