2014-09-01 183 views
-1

此表单提交不工作,谁能帮我...形式不提交/工作

我使用的引导CSS和试图提交一份简单的表格,有一个小问题,但我可以“T检测到问题,请大家帮忙

<div class="container"> 
    <div class="thumbs askus container col-md-6 col-md-offset-4"> 
     <form id="logfrm" action="" method="post" class="form-horizontal"> 
      <div class="form-group"> 
      <label for="inputEmail3" class="col-sm-2 control-label">Username</label> 
      <div class="col-sm-4"> 
       <input type="text" name="unm" class="form-control" id="inputUser" placeholder="Username"> 
      </div> 
      </div> 
      <div class="form-group"> 
      <label for="inputPassword3" class="col-sm-2 control-label">Password</label> 
      <div class="col-sm-4"> 
       <input type="password" name="pwd" class="form-control" id="inputPassword" placeholder="Password"> 
      </div> 
      </div> 
      <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-4"> 
       <div class="checkbox"> 
       <label> 
        <input type="checkbox"> Remember me 
       </label> 
       </div> 
      </div> 
      </div> 
      <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-4"> 
       <button class="btn btn-default" >Sign in</button> 
      </div> 
      </div> 
     </form> 
    </div> 
</div> 

PHP代码的形式处理

if (isset($_POST['unm'])) { 
if ($_POST['unm']=="admin" && $_POST['pwd']=="xxxxxx") { 
    echo '<script type="text/javascript">alert("Hi Admin");</script>'; 
    header('Location: home.php'); 
} 
else{ 
    echo '<script type="text/javascript">alert("Unknown Username/Bad password");</script>'; 
} 

}

+0

那么什么不起作用? – Daan 2014-09-01 10:32:12

+1

表单标签中的“操作”字段为空。把那里的PHP脚本地址。 – ojovirtual 2014-09-01 10:35:26

+0

action =“”同一页? – 2014-09-01 10:35:30

回答

1

你只是错过了动作URL,这样表单提交不工作......我刚刚从动作变更表单动作标签=“”行动=“action.php的”其中action.php是包含您的PHP代码来处理HTML表单的文件。使用下面的代码,这将解决您的问题。

home.php

<?php 
    if(isset($_POST['submit_button'])) 
    { 

if ($_POST['unm']=="admin" && $_POST['pwd']=="xxxxxx") { 
    echo '<script type="text/javascript">alert("Ok");</script>'; 
    header('Location:home.php'); 
} 
else{ 
    echo '<script type="text/javascript">alert("Unknown Username/Bad password"); if(confirm("Unknown Username/Bad password")){document.location.reload(true);}</script>'; 

} 
} 

else 
{ 

?> 

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Bootstrap 101 Template</title> 

    <!-- Bootstrap --> 
    <!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> 

<!-- Optional theme --> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> 

<!-- Latest compiled and minified JavaScript --> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> 
</head> 
<body><br/><br/><br/><br/> 
    <div class="container"> 
    <div class="thumbs askus container col-md-6 col-md-offset-4"> 
     <form id="logfrm" method="post" class="form-horizontal" action="home.php"> 
      <div class="form-group"> 
      <label for="inputEmail3" class="col-sm-2 control-label">Username</label> 
      <div class="col-sm-4"> 
       <input type="text" name="unm" class="form-control" id="inputUser" placeholder="Username"> 
      </div> 
      </div> 
      <div class="form-group"> 
      <label for="inputPassword3" class="col-sm-2 control-label">Password</label> 
      <div class="col-sm-4"> 
       <input type="password" name="pwd" class="form-control" id="inputPassword" placeholder="Password"> 
      </div> 
      </div> 
      <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-4"> 
       <div class="checkbox"> 
       <label> 
        <input type="checkbox"> Remember me 
       </label> 
       </div> 
      </div> 
      </div> 
      <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-4"> 
       <button type="submit" class="btn btn-default" name="submit_button" >Sign in</button> 
      </div> 
      </div> 
     </form> 
    </div> 
</div> 
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> 
    </body> 
    <?php } ?> 
</html> 
+0

我正在提交d表格到同一页 – sarath 2014-09-01 11:52:25

+0

@SarathMohan我改变了我的代码,因为你需要... – 2014-09-03 04:37:59

+0

问题已解决... bt我没有得到d实际麻烦造成的原因,无论如何它被解决了 – sarath 2014-09-03 05:36:52

1

如果你的这个表单的php在同一个页面上,那么将这个操作指向同一页面是有意义的。这样,表单将被发送到页面的刷新版本,PHP将从该页面中检索并处理它。

所以 - 如果你形成一个称为form.php的

然后页面上应该是

<form id="logfrm" action="form.php" method="post" class="form-horizontal"> 

您可以使用Firebug看到这一切都是监控$ _ POST [“UMN”]发送正确

+0

我已经尝试过,页面没有导航到其他页面提交 – sarath 2014-09-01 11:20:15

+0

在页面上的PHP的顺序是重要的 - 当表单重新提交到同一页面时,它将运行从页面顶部的脚本下来,所以它可能是在页面上定位的PHP的问题 - 在同一页上的PHP在哪里? – Mobaz 2014-09-02 22:44:05