[英]Outputting html form data
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代码:
<?php
if (!empty($_POST["email"]))
file_put_contents("emails.txt", file_get_contents("emails.txt") . "\n" . $_POST["email"]);
?>
在问这里之前,我尝试了几种方法,但没有一种有效。 单击按钮时,它会加载 php 代码并在浏览器上显示一个空白页面。
在开始之前,您必须做很多事情。
将表单的action
属性设置为.php
文件。
<form class="form-inline signup" role="form" action="write.php" method="post">
为<input />
元素提供name
属性。
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address" name="email" />
在write.php
(或您使用的任何 PHP 文件)中,实际写入该文件。
<?php if (!empty($_POST["email"])) file_put_contents("emails.txt", file_get_contents("emails.txt") . "\\n" . $_POST["email"]); ?>
最后但并非最不重要的是,请在服务器上而不是在浏览器中运行它:
http://localhost/file.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.