简体   繁体   English

输出html表单数据

[英]Outputting html form data

HTML Code: HTML代码:

<form class="form-inline signup" role="form" action="script.php" method="post">
  <div class="form-group">
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address" name="email" > 
  </div>
  <button type="submit" class="btn btn-theme">Get notified!</button>
</form>

PHP Code: PHP代码:

<?php
  if (!empty($_POST["email"]))
    file_put_contents("emails.txt", file_get_contents("emails.txt") . "\n" . $_POST["email"]);
?>

I tried several methods before asking here but none works.在问这里之前,我尝试了几种方法,但没有一种有效。 When the button is click it loads the php code and shows a blank page on the browser.单击按钮时,它会加载 php 代码并在浏览器上显示一个空白页面。

You have to do a lot of things before you can start.在开始之前,您必须做很多事情

  1. Set the action attribute of the form to a .php file.将表单的action属性设置为.php文件。

     <form class="form-inline signup" role="form" action="write.php" method="post">
  2. Give a name attribute to the <input /> element.<input />元素提供name属性。

     <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address" name="email" />
  3. In the write.php (or whatever PHP file you use), actually write to the file.write.php (或您使用的任何 PHP 文件)中,实际写入该文件。

     <?php if (!empty($_POST["email"])) file_put_contents("emails.txt", file_get_contents("emails.txt") . "\\n" . $_POST["email"]); ?>
  4. Last but not least, please run this on the server and not in browser:最后但并非最不重要的是,请在服务器上而不是在浏览器中运行它

     http://localhost/file.php

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

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