区别:<! - ?php echo htmlspecialchars($ _ SERVER [“PHP_SELF”]);? - >和外部PHP文件在action属性中?

时间:2017-11-01 10:37:01

标签: php html forms echo action

我在index.php文件中有这段代码 -

<form class="speaker-form" action="form.php" method="post">

到处都在读我的代码应该是这样的 -

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

我想链接外部(form.php)文件。我是否在外部文件中编写超全局?我似乎无法找到任何这方面的例子。

感谢。

1 个答案:

答案 0 :(得分:0)

示例: 将以下内容另存为sample.html

<!DOCTYPE html>
<html>
<body>
<form id="myForm" action="test.php">
            <div id="Level1_Form"> <!--Use divs to space-->
                <div id="ContainInputDiv1-1">
                    <p class="level1InputP">First Name: <span class="formError" id="FNameErrorP"></span></p>
                    <input type="text" class="Level1InputTxt" id="fName"/>
                </div>
                <div id="ContainInputDiv1-2">
                    <p class="level1InputP">Last Name: <span class="formError" id="LNameErrorP"></span></p>
                    <input type="text" class="Level1InputTxt" id="lName"/>
                </div>
                <div id="ContainInputDiv1-3">
                    <p class="level1InputP">E-Mail: <span class="formError" id="ErrorEmailP"></span></p>
                    <input type="text" class="Level1InputTxt" id="eMail"/>
                    <p id="ErrorEMailP"></p>
                </div>
                <div id="ContainInputDiv1-4">
                    <p class="level1InputP">Phone Number: <span class="formError" id="ErrorPhoneNumP"></span></p>
                    <input type="text" class="Level1InputTxt" id="phoneNumber"/>
                </div>
            </div>
        </form>
</body>
</html>

将以下内容保存为test.php

<?php
print_r($_POST);
 ?>
相关问题