[英]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.