我想分步生成页面;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>
看来我生成错误了。首先,文件应以 *.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>
声称它正在工作的最好例子是:php 中的表单生成器