【发布时间】:2018-02-15 10:59:24
【问题描述】:
我也用 POST 和 GET 方法尝试了我的代码,但我看不到这些方法的任何价值。提交表单后,页面刷新,但我的 .php 文件写出:Array ( )
我在 Chrome 开发者工具中寻找价值,但网络选项卡内没有“表单数据”,只有一般的响应标头和请求标头。
我的 HTML 代码:
<!--Modal: Login Form-->
<form id="loginModal" name="loginModal" class="modal fade modal-full-height" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
data-backdrop="static" action="/main.php" method="POST">
<div class="modal-dialog cascading-modal" role="document">
<!--Content-->
<div id="loginModalDiv" class="modal-content">
<!--Header-->
<div class="modal-header myModalHeader">
<h4 class="title"><i class="fa fa-user-lg"></i> Login:</h4>
</div>
<!--Body-->
<div class="modal-body">
<div class="md-form form-sm">
<i class="fa fa-envelope prefix"></i>
<input type="text" id="logF_email" name="email" class="form-control">
<label for="logF_email">E-mail address:</label>
</div>
<div class="md-form form-sm">
<i class="fa fa-lock prefix"></i>
<input type="password" id="logF_passw" name="password" class="form-control">
<label for="logF_passw ">Password:</label>
</div>
<div class="text-center mt-2">
<div id="errorLogin"></div>
<button id="btnLogin" type="submit" class="btn btn-default myModalBtn">Belépés <i class="fa fa-sign-in ml-1"></i></button>
</div>
</div>
<!--Footer-->
<div id="footerLogin" class="modal-footer">
<div class="options text-center text-md-center mt-1">
<p>You don't have an account? <a class="loginToSignUp myGreenClass" data-toggle="modal" href="#"> Sign up!</a></p>
<p>Forget <a class="forgetPassword myGreenClass" data-toggle="modal" href="#"> password?</a></p>
</div>
<button type="button" class="btn btn-outline-default waves-effect ml-auto myModalBtn" data-dismiss="modal">Close</button>
</div>
</div>
<!--/.Content-->
</div>
</form>
...和 .php 文件:
$email =""; $password ="";
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_POST);
$email = $_POST['email'];
$password = $_POST['password'];
print_r($email);
print_r($password);
if ($email=="") {echo "<br> 'no data'";}
else {echo "Your email: ".$email;}
}
我是 PHP 和表单处理的初学者,所以我想我可能会错过一些东西。 我尽量避免小错误,因此我的代码包含:
- 表单的动作和方法属性
- 输入字段的名称属性
-
type="submit"提交按钮
if ( $_POST ){if (!empty($_POST)){
也不工作
知道有什么问题吗?
【问题讨论】:
-
将 method="GET" 更改为 method="post"
-
这是post,我也试试get和post。
-
它们都不起作用
-
我的意思是如果我改变 php 和 html 来发布
-
下面所有的答案都是一样的;)