我想逐步生成页面; form1生成form2,form2生成form3。这可能吗?

时间:2013-12-19 13:12:28

标签: php forms post dynamic form-generator

我想按步骤生成页面; form1生成form2,form2生成form3。 这可能吗?

  <!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>

1 个答案:

答案 0 :(得分:0)

我似乎错误地生成了。 首先,文件应使用* .php扩展名,而不是html

其次,我使用错误的语法,我不应该回显HTML行,我应该用HTML编写并在需要时打破php appart。这种语法有效:

<!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>

声称它有效的最好例子是: Form generator in php