Gintare Statkute
Gintare Statkute

Reputation: 687

I would like generate page in steps; form1 generates form2, form2 generates the form3. Is this possible?

I would like generate page in steps; form1 generates form2, form2 generates the form3. Is this possible?

  <!DOCTYPE html><html><head><title> some </title></head><body>

     <form name="form1"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "> 
    print "in form1";
    <input type="submit" id="fsi1" value="fsv1" name="fsn1"> <br>
    </form>

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

        if (!empty($_POST['fsn1'])) {
    print '<form name="form2"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "> echo "in form2"; </form><br>';
    print '<input type="submit" id="fsi2" value="fsv2" name="fsn2"> <br>';
    }

        if (!empty($_POST['fsn2'])) {
    print '<form name="form3"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "> echo "in form3"; </form><br>';
    print '<input type="submit" id="fsi3" value="fsv3" name="fsn3"> <br>';
    }

    }
    ?>

    </body></html>

Upvotes: 0

Views: 260

Answers (1)

Gintare Statkute
Gintare Statkute

Reputation: 687

It seems i generate wrongly. First the file should be named with *.php extension, not html

Second, i use wrong syntax, i should not echo HTML lines, i should write in HTML and break php appart whenever it is needed.This syntax works:

<!DOCTYPE HTML >
<html>
<head>
<title></title>
<meta name="" content="">
</head>
<body>

     <form name="form1"  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
    print "in form1";
    <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 echo "in form2"; ?>
    <input type="submit" id="fsi2" value="fsv2" name="fsn2"> 
        </form><br>; 

    <?php }} ?>

</body>
</html>

The best example, which claims it is working is: Form generator in php

Upvotes: 0

Related Questions