【问题标题】:Cannot handle a form in php无法在php中处理表单
【发布时间】:2018-01-08 14:34:21
【问题描述】:

我现在正在学习 php,但我被困在一个处理表单提交操作的地方。 我输入我正在尝试将用户名存储在$_GET['firstname'] 变量中。但它是空的。我的意思是,在检查$_GET['firstname']isset 之后,我得到了错误。我的错在哪里?

<body>
    <div class="container">
        <div class="section back">
            <form class="form myform" action="addcustomer.php" method="get">
                <span class="myformtitle">
                    Add new User
                </span>
                <div class="form-group">
                    <div class="col validate-input">
                        <span class="label-input">Firstname</span>
                        <input id="firstname" class="input myinput" type="text" name="firstname" placeholder="Enter your firstname" value="<?php if (isset($_GET['firstname'])) echo $_GET['firstname']?>">
                        <span class="focus-input"></span>
                    </div>
                </div>
                <div class="col col-btn">
                    <button type="button" name="submit" class="btn sb-btn btn-block">
                        <span class="btn-sp">
                            Submit
                        </span>
                    </button>
                </div>
            </form>
        </div>
    </div>

    <?php
    if (isset($_GET['firstname'])) {
        echo '<script>console.log("' . $_GET['firstname'] . '")</script>';
    } else {
        echo '<script>console.log("no name")</script>';
    }
    ?>
</body>

【问题讨论】:

  • &lt;button type="button" >>> &lt;button type="submit"
  • @FunkFortyNiner 非常感谢
  • 不客气。

标签: php


【解决方案1】:

将您的按钮类型从 button 更改为 submit

  • button 类型用于 Javascript (JS)。

  • submit 类型用于处理 PHP(表单)指令。

【讨论】:

    猜你喜欢
    • 2014-09-14
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多