HTML表单不起作用 - HTML <form>

时间:2017-05-19 07:33:45

标签: php html css

我是StackOverflow的新手,但我是一个伟大的开发者。 我正在为我的192.168.1.230本地服务器制作一个HTML表单,但是当我点击提交按钮(代码底部附近)时,我的html代码遇到了这个问题请尽可能使用帮助。我不认为你需要我的CSS,但问我是否这样做,我将回复所有CSS代码。

<html>
<head>
<title>192.168.1.230 - Become Admin</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<form class="form-horizontal">
<fieldset>

<!-- Form Name -->
<legend style=text-align:center><br><h2><strong>192.168.1.230 - Become Admin</strong></h2><br></legend>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="textinput">Full Name</label>  
  <div class="col-md-4">
  <input id="textinput" name="textinput" type="text" placeholder="e.g John Doe" class="form-control input-md" required="">

  </div>
</div>

<!-- Password input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="passwordinput">Password</label>
  <div class="col-md-4">
    <input id="passwordinput" name="passwordinput" type="password" placeholder="e.g helloworld123" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="email">Your Email:</label>  
  <div class="col-md-4">
  <input id="email" name="email" type="text" placeholder="e.g johndoe@gmail.com" class="form-control input-md" required="">

  </div>
</div>

<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="selectbasic">Gender</label>
  <div class="col-md-4">
    <select id="selectbasic" name="selectbasic" class="form-control">
      <option value="Male">Male</option>
      <option value="Female">Female</option>
      <option value="Other">Other</option>
    </select>
  </div>
</div>

<!-- Button -->
<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for="singlebutton"></label>
  <div class="col-md-4">
    <button id="singlebutton" name="singlebutton" class="btn btn-primary" action="../php/search.php" method="post">Submit</button>
  </div>
</div>

</fieldset>
</form>
</html>

3 个答案:

答案 0 :(得分:1)

您需要在表单标记

中添加此action="../php/search.php" method="post"

这样做:

<form class="form-horizontal" action="../php/search.php" method="post">

然后将您的按钮更改为:

<button id="singlebutton" name="singlebutton" class="btn btn-primary" type="submit">Submit</button>

在你的php脚本中,检查如下的简历:

<?php
if(isset($_POST['singlebutton'])){//name of button
   $password = $_POST['passwordinput']; //
   $name = $_POST['textinput'];
   $email = $_POST['email'];
  //etc. Remember to access the name attribute as it will contain the value from your form
print_r($_POST);//returns associative array(key => value)
}

?>

我看到你有一个密码字段,请不要以明文形式存储密码,请使用php的password_hash

答案 1 :(得分:0)

你必须通过action&amp; method标记上的form属性而不是按钮

<html>
<head>
    <title>192.168.1.230 - Become Admin</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<form class="form-horizontal" action="../php/search.php" method="post">
    <fieldset>

        <!-- Form Name -->
        <legend style=text-align:center><br>
            <h2><strong>192.168.1.230 - Become Admin</strong></h2><br></legend>

        <!-- Text input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="textinput">Full Name</label>
            <div class="col-md-4">
                <input id="textinput" name="textinput" type="text" placeholder="e.g John Doe" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Password input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="passwordinput">Password</label>
            <div class="col-md-4">
                <input id="passwordinput" name="passwordinput" type="password" placeholder="e.g helloworld123" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Text input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="email">Your Email:</label>
            <div class="col-md-4">
                <input id="email" name="email" type="text" placeholder="e.g johndoe@gmail.com" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Select Basic -->
        <div class="form-group">
            <label class="col-md-4 control-label" for="selectbasic">Gender</label>
            <div class="col-md-4">
                <select id="selectbasic" name="selectbasic" class="form-control">
          <option value="Male">Male</option>
          <option value="Female">Female</option>
          <option value="Other">Other</option>
        </select>
            </div>
        </div>

        <!-- Button -->
        <!-- Button -->
        <div class="form-group">
            <label class="col-md-4 control-label" for="singlebutton"></label>
            <div class="col-md-4">
                <button id="singlebutton" name="singlebutton" class="btn btn-primary" type="submit">Submit</button>
            </div>
        </div>

    </fieldset>
</form>
</html>

答案 2 :(得分:0)

所以工作代码感谢你们两个:

<html>
<head>
    <title>192.168.1.230 - Become Admin</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<form class="form-horizontal" action="../php/search.php" method="post">
    <fieldset>

        <!-- Form Name -->
        <legend style=text-align:center><br>
            <h2><strong>192.168.1.230 - Become Admin</strong></h2><br></legend>

        <!-- Text input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="textinput">Full Name</label>
            <div class="col-md-4">
                <input id="textinput" name="textinput" type="text" placeholder="e.g John Doe" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Password input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="passwordinput">Password</label>
            <div class="col-md-4">
                <input id="passwordinput" name="passwordinput" type="password" placeholder="e.g helloworld123" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Text input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="email">Your Email:</label>
            <div class="col-md-4">
                <input id="email" name="email" type="text" placeholder="e.g johndoe@gmail.com" class="form-control input-md" required="">

            </div>
        </div>

        <!-- Select Basic -->
        <div class="form-group">
            <label class="col-md-4 control-label" for="selectbasic">Gender</label>
            <div class="col-md-4">
                <select id="selectbasic" name="selectbasic" class="form-control">
          <option value="Male">Male</option>
          <option value="Female">Female</option>
          <option value="Other">Other</option>
        </select>
            </div>
        </div>

        <!-- Button -->
        <!-- Button -->
        <div class="form-group">
            <label class="col-md-4 control-label" for="singlebutton"></label>
            <div class="col-md-4">
                <button id="singlebutton" name="singlebutton" class="btn btn-primary" type="submit">Submit</button>
            </div>
        </div>

    </fieldset>
</form>
</html>

非常感谢!