duanbiao4035 2016-10-18 14:16
浏览 58

如何将表单输入发送到文本文件和/或数据库?

So I have made a "Coming Soon" page and I have a form to sign up for a newsletter but I cant seem to get the coding right.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Coming Soon to a Browser Near You</title>        
        <link rel="stylesheet" type="text/css" href="style.css" />

        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script>
        <script type='text/javascript' src='javascripts/jquery.tipsy.js'></script>
        <script type='text/javascript'>
        $(function() {
            $('#tipsy').tipsy({fade: true, gravity: 's'});
        });
        </script>
        <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

    </head>
    <body>
        <div class="wrapper">
<!--            <img src="images/logo.png" alt="YourLogo" title="YourLogo"/>
-->         <h1>SirAethon</h1>
            <div class="hr"></div>
            <h3>Coming Soon to a Browser Near You</h3>
            <p>Unfortunately, we’re not quite ready yet. <strong> But, you can see our progress below:</strong></p>

            <section class="progress">
                <div class="progress-bar-container" id="tipsy" title="8% Complete"> <!-- Edit this title for the tooltip pop up -->
                    <article class="progress-bar" style="width:8%"  ></article> <!-- Edit the width percentage value to indicate progress -->
                </div>
                <article class="txt-launch-day-hat"></article>
            </section>

            <div class="hr"></div>
            <section class="mailing-list">
                <h2>Want to be the first to know when we're ready?</h2>
                <form>
                    <input type="text" value="your@email.com" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
                    <input type="submit" value="Subscribe"> 
                </form>
            </section><div class="clear"></div>
            <div class="hr"></div>

            <p class="credit">Designed by <a href="http://siraethon.com">SirAethon</a></p>
        </div>
    </body>
</html>

That is my index.html page. I want the form section to be able to take an email and confirm that it is an actual email then put that email into a text file so that I can come along later and take the emails so I can send a mass email at once.

        <section class="mailing-list">
            <h2>Want to be the first to know when we're ready?</h2>
            <form>
                <input type="text" value="your@email.com" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
                <input type="submit" value="Subscribe"> 
            </form>
        </section>

Above is the mailing list section along with the form.

(Any help is highly appreciated! Thank you in advance!)

EDIT1: So I have gotten it to work but now it says "13 bytes written to file" once you click the subscribe button how do I fix it from saying this and make it say something else like thank you for subscribing?

I used these coding:

Form:

        <form action="php/signup.php" method="POST">
            <input name="field1" type="text" value="your@email.com" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
            <input type="submit" name="submit" value="Save Data">
        </form>

signup.php:

<?phppublic_html/the-fam.com/php/signup.php
if(isset($_POST['field1'])) {
    $data = $_POST['field1'];
    $ret = file_put_contents('emails.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        echo "$ret bytes written to file";
    }
}
else {
   die('no post data to process');
}

EDIT2: So i tried to fix it saying bytes written to file and now its not displaying anything nor is it writing to file: "$ret bytes written to file" I removed that part then replaced it and nothing is happening but I replaced it back and still nothing is happening

If you want to look at the site your self it is http://the-fam.com

  • 写回答

2条回答 默认 最新

  • dqc18251 2016-10-18 14:21
    关注

    Your form has no action or method, therefore it does nothing. You probably want method="post" and action="some_script.php", where the some_script.php file will handle doing whatever you want with the data (validation, save to file, save to database, etc.). You will also want name="email" or something along those lines as an attribute on your text input. That way you can access it via $_POST['email']

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端