简体   繁体   English

我的表格怎么了?

[英]What's wrong with my form?

I had a form which was unstyled, so I decided to style it a bit. 我有一个未设置样式的表单,因此我决定对其进行样式设置。

Form that does nothing: 无效的表格:

<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>

Working 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>

I'm not really sure what's wrong. 我不太确定这是怎么回事。

The broken form doesn't POST the data, thus it doesn't display it. 损坏的表单不会发布数据,因此不会显示它。

I think I finally understand your issue. 我想我终于明白了您的问题。 Its not that the form doesn't POST. 它不是表单不发布。 It goes to the next page. 转到下一页。 No, its that the values get lost. 不,它的价值迷失了。

So why do the values get lost? 那么为什么价值观会迷失呢? Because you have no name attribute on your inputs! 因为您的输入中没有name属性!

This: 这个:

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

Should be: 应该:

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

In fact, shouldn't placeholder be value ? 实际上, placeholder不应该value吗?

This line: 这行:

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

is missing the /> at the end. 末尾缺少/>

Also, in the working one, you have a 另外,在工作中,您有一个

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

The one that is not working: 一个不起作用的:

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

You are missing an input hidden or something like that. 您缺少隐藏的输入或类似内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM