在另一个内部生成表单

时间:2014-02-02 21:18:09

标签: php

我想知道如何在里面生成另一个表单。

这是代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="content-equip" content="text/html; charset=UFT-8">
        <link rel="stylesheet" href="main.css" type="text/css">
        <title>Formulario</title>
    </head>
    <body>
        <div class='titleClass'></div>
            <?php 
                $validateUser = false;
                $ValidateStadistic = false;
                if (isset($_POST["enter"])) {
                    if ($_POST["passT"] == "username" and $_POST["userT"] == "password") {
                        // pass and user CORRECT; none DIV 
                        $validateUser = "none";
                        echo "<form action='echo $_SERVER['PHP_SELF']' method='POST'>";
                        echo "<div class='look'><fieldset><legend>Stadistic</legend>";
                        echo "<input type='radio' name='radio' value='visitas'>view visits";
                        echo "</br><input type='radio' name='radio' value='usuarios'>view user ";
                        echo "</br><input type='radio' name='radio' value='candidatos'>view all";
                        echo "</br></br><input type='submit' name='view' value='view'>";
                        echo "</fieldset></div>";
                        echo "</form>";
                    } else { 
                        echo "<div class='error'>Password or user error</div></br>"; 
                    }
                }
                if (isset($_POST['view'])) {
                    echo $_POST['radio'];
                }

            ?>
        <div <?php echo "style='display: $validateUser';"?> >
            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
                <div class='insertUser'>
                <fieldset>
                <legend>User and password</legend>
                    <input type="text" name="userT" placeholder="user"> 
                    </br></br>
                    <input type="password" name="passT" placeholder="password">
                    </br></br><input type="submit" name="enter" value="enter">
                </fieldset>
                </div>
            </form>
        </div>
    </body>
</html>

问题在于:

echo "<form action='echo $_SERVER['PHP_SELF']' method='POST'>";

有解决方案吗?谢谢!!

1 个答案:

答案 0 :(得分:1)

echo "<form action='echo $_SERVER['PHP_SELF']' method='POST'>";

更改为

echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>";

echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='POST'>";