Monday, 26 May 2014

Passing PHP form variables from one page to other pages

 File:form.php

<form method="post" action="form2.php">
    <input type="text" name="name">
    <input type="text" name="email_address">
    <input type="submit" value="Go To Step 2">
</form>







<?php

//let's start the session  File:form2.php
session_start();

//now, let's register our session variables
 $name = $_SESSION['name'];
$email = $_SESSION['email_address'];


//finally, let's store our posted values in the session variables
$_SESSION['name'] = $_POST['name'];
$_SESSION['email_address'] = $_POST['email_address'];

?>
<form method="post" action="form3.php">
<input type="radio" name="membership_type" value="Free">
<input type="radio" name="membership_type" value="Normal">
<input type="radio" name="membership_type" value="Deluxe">
<input type="checkbox" name="terms_and_conditions">
<input type="submit" value="Go To Step 3">
</form>




<?php

//let's start the session  File:form3.php
session_start();

//now, let's register our session variables

$membership_type = $_SESSION['membership_type'];
$terms_and_conditions = $_SESSION['terms_and_conditions'];
//session_register('membership_type');
//session_register('terms_and_conditions');

//finally, let's store our posted values in the session variables
$_SESSION['membership_type'] = $_POST['membership_type'];
$_SESSION['terms_and_conditions'] = $_POST['terms_and_conditions'];

?>
<form method="post" action="form_process.php">
<input type="text" name="name_on_card">
<input type="text" name="credit_card_number">
<input type="text" name="credit_card_expiration_date">
<input type="submit" value="Finish">
</form>




<?php
 //form_process.php
//let's start our session, so we have access to stored data
    session_start();
   
    $_SESSION['name_on_card'] = $_POST['name_on_card'];
     $_SESSION['credit_card_number'] = $_POST['credit_card_number'];
      $_SESSION['credit_card_expiration_date'] = $_POST['credit_card_expiration_date'];
   
   

 echo $name = $_SESSION['name'];
 echo $email = $_SESSION['email_address'];
echo $membership_type = $_SESSION['membership_type'];
echo $terms_and_conditions = $_SESSION['terms_and_conditions'];


 echo $name_on_card = $_SESSION['name_on_card'];
echo $credit_card_number = $_SESSION['credit_card_number'];
echo $credit_card_expiration_date = $_SESSION['credit_card_expiration_date'];

 ?>

No comments:

Post a Comment