Gintare Statkute
Gintare Statkute

Reputation: 687

Ways to save variables in the page and share them among forms, not using sessions

I know about sessions. Would like to ask if there are more ways to save variables in the page and share them among forms. Example code, which does not work, because i do not know how to share varf1, varf2, varf3 in page not using sessions:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
</head>
<body>

<!--     Question: how to access variables varf1, varf2, varf3 in all three forms?  -->
<!-- <?php  $varf1= $_POST['varf1']; $varf2= $_POST['varf2']; $varf3= $_POST['varf3']; $_POST['fsn1']=""; $_POST['fsn2']=""; ?>  -->


<?php  $varf1=$_POST['varf1']=$varf2=$_POST['varf2']=$varf3=$_POST['varf3']=""; ?>

<!--     form1 generates form2, and form 2 generates form3  -->

    <form name="form1"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
        <?php $varf1="varf1"; 
        echo "in form1, var1=".$varf1.",  var2=".$varf2.",  var3=".$varf3; ?>
    <input type="submit" id="fsi1" value="fsv1" name="fsn1"> <br>
    </form>

 <?php  if($_SERVER["REQUEST_METHOD"] == "POST") {  

 if(!empty($_POST['fsn1'])) { ?>

    <form name="form2"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "> 
        <?php $varf2="varff2"; 
        echo "in form2, var1=".$varf1.",  var2=".$varf2.",  var3=".$varf3; ?>
    <input type="submit" id="fsi2" value="fsv2" name="fsn2"> 
        </form><br>; 
        <?php } // if(!empty($_POST['fsn1'])  

  if(!empty($_POST['fsn2'])) { ?>

    <form name="form3"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "> 
        <?php $varf3="varff3"; 
        echo "in form3, var1=".$varf1.",  var2=".$varf2.",  var3=".$varf3; ?>
    <input type="submit" id="fsi3" value="fsv3" name="fsn3"> 
        </form><br>; 
      <?php } // if(!empty($_POST['fsn2'])) 

} // if($_SERVER["REQUEST_METHOD"
        ?>

</body>
</html>

Upvotes: 0

Views: 55

Answers (1)

Guntram Blohm
Guntram Blohm

Reputation: 9819

You can always use

<input type="hidden" name="varf1" value="<?php echo $varf1?>">

in each of the forms.

Upvotes: 2

Related Questions