doucong7963 2016-03-27 13:38
浏览 52
已采纳

表格不发布 - PHP

I want to make this form where people can send a email to me. I've done this before but this time it won't post... I won't get a error message or anything like that. Even my custom made error messages won't show up.

<?php
            $err = "<br/>";
            if (isset($_POST['submit'])) {
                $name = $_POST['name'];
                $email = $_POST['email'];
                $message = $_POST['message'];
                if (!empty($name) && !empty($email) && !empty($message)) {
                    if (strstr($name, " ")) {
                        if(strlen($email) >=5 && strstr($email, "@") && strstr($email, ".")) {

                        } else {
                            $err = "<p style='color:#b30000'>Fill in a valid email!</p>";
                        }
                    } else {
                        $err = "<p style='color:#b30000'>Fill in a valid name!</p>";
                    }
                } else {
                    $err = "<p style='color:#b30000'>Fill in all the fields!</p>";
                }
            } else {$name = ''; $email = ''; $message = '';}

            echo $err . "
            <form id='form' action='#form' method='post'>
                <p>Full Name:</p>
                <input class='input' type='text' name='name' placeholder=' Dirk Vondiek' value=". $name . ">
                <p>E-Mail:</p>
                <input class='input' type='text' name='email' placeholder=' example@domain.com' value=". $email . ">
                <p>Your Message:</p>
                <textarea class='textarea' name='message' placeholder=' Can you pls add me on steam?'>". $message ."</textarea>
                <center><input class='submit' type='submit' name'submit' value='Send'></input></center>
            </form>
            "
        ?>
  • 写回答

3条回答 默认 最新

  • duanposhi3641 2016-03-27 13:41
    关注

    action='#form', it's invalid for an action syntax, so change that to action="" or action="handler.php" if you later decide to use two seperate files.

    Edit for above: After testing for myself, that does indeed work, but the major culprit here is that you have a typo here name'submit' and your conditional statement
    if (isset($_POST['submit'])) {...} will never happen because of it.

    • You forgot the equal sign.

    So modify it to read as name='submit'.

    You also have </input> you can safely get rid of it, it's not a valid closing tag.

    And you forgot to close this statement (but in testing this didn't throw me an error and I find that rather a bit bizarre).

    </form>
            "
    ?>
    

    So.

    </form>
            ";
    ?>
    

    That alone with error reporting would have thrown you something about it.

    Nota:

    However, if you have more code below the </form>" line, then you will get a parse error such as:
    (Nota: I added an echo "Testing"; for this example error) but will throw you a parse error related to what you may be using:

    Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';'

    As you mention in your question that it's meant to send mail with, but that wasn't included in your original post.

    If you do have more code below that line and inside the same <?php ...?> tags, then you will need to close off that statement as stated in my answer.

    For example.

    This will throw a parse error:

    </form>
            "
    
    mail();
    ?>
    

    This won't throw an error (valid) so it needs to be closed (mail() is just a fill-in example here).

    </form>
            ";
    
    mail();
    ?>
    

    Add error reporting to the top of your file(s) which will help find errors.

    <?php 
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    // Then the rest of your code
    

    Sidenote: Displaying errors should only be done in staging, and never production.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥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做蓝牙接受端