我的表格有什么问题?

时间:2014-12-12 00:20:47

标签: php

我有一张没有样式的表格,所以我决定把它设计一下。

无效的表格:

<form class="form-horizontal" role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  <div class="form-group">
    <label for="username" class="col-sm-2 control-label">Username</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" placeholder="<?php echo $_POST['username']; ?>">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">API Key</label>
    <div class="col-sm-10">
      <p class="form-control-static"><?php if(strpos(file_get_contents("keys.php"),base64_encode($_POST['username'])) !== false) {echo "API Key already exists";} else { echo base64_encode($_POST['username']); }?></p>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Get API Key</button>
    </div>
  </div>
</form>

工作表格:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  Username: <input type="text" name="username" value"<?php echo $_POST['username']; ?>" /><br /><br />
  Key: <input type="text" value="
  <?php if(strpos(file_get_contents("./keys.php"),base64_encode($_POST['username'])) !== false) {
    echo "API Key already exists";
  } else { echo base64_encode($_POST['username']); }?>" readonly /><br />
  <input type="submit" />
</form>

我不确定是什么错误。

破碎的表格不会发布数据,因此不会显示数据。

2 个答案:

答案 0 :(得分:2)

我想我终于理解了你的问题。它不是表格不POST。它转到下一页。不,它的价值就会丢失。

那么为什么价值观会迷失?因为您的输入没有name属性!

此:

<input type="text" class="form-control" placeholder="<?php echo $_POST['username']; ?>">

应该是:

<input type="text" name="username" class="form-control" placeholder="<?php echo $_POST['username']; ?>">

事实上,placeholder不应该value

答案 1 :(得分:-1)

这一行:

<input type="text" class="form-control" placeholder="<?php echo $_POST['username']; ?>">

最后缺少/>

另外,在工作中,你有一个

Key: <input type="text" value="...

不工作的那个:

<p class="form-control-static"><?php if(strpos(file_get_contents...

您错过了隐藏的输入或类似的内容。

相关问题