HTML Code:
<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
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.
You have to do a lot of things before you can start.
Set the action
attribute of the form to a .php
file.
<form class="form-inline signup" role="form" action="write.php" method="post">
Give a name
attribute to the <input />
element.
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address" name="email" />
In the write.php
(or whatever PHP file you use), actually write to the file.
<?php if (!empty($_POST["email"])) file_put_contents("emails.txt", file_get_contents("emails.txt") . "\\n" . $_POST["email"]); ?>
Last but not least, please run this on the server and not in browser:
http://localhost/file.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.