douxiong3234 2019-04-01 14:27
浏览 58
已采纳

试图通过按钮发布

I Have tried many solutions posted on stack overflow and non of them have worked.

It could just be me but i tried it on a separate file and it worked but if i use my current site with nice css it won't work

I Have tried the exact code on LAEPHP and it worked but when i added my code as you can see below it does not display anything when the button is clicked and it does not even refresh the page on click

<form action="" method="post">
    <div class="form-group">
        <label>Username</label>
        <input class="au-input au-input--full" type="email" name="target" placeholder="Example">
    </div>

    <div class="form-group">
        <label>API key</label>
        <input class="au-input au-input--full" type="text" name="key" placeholder="X7UI-9H2D-IZAS">
    </div>

    <?php

        $key= $_POST['key'];
        $send= $_POST['send'];

        if ($send) {
            if (!empty($key)) {
                echo 'The key you entered is ' . $key;
            }
            else {
                echo 'You did not enter a key. Please enter a key into this form field.';
            }
        }
    ?>

    <button class="subscribe btn btn-primary btn-block" name="send" type="submit">Check Key</button>
</form>
  • 写回答

2条回答 默认 最新

  • 普通网友 2019-04-01 14:47
    关注

    The problem I see is that you're checking if the button was sent and isn't "falsy". Since you don't have a value-attribute on the button, it will be an empty string, which is a "falsy" value, meaning that the first if-statement will never evaluate as true.

    Try changing your code to:

    <?php
    // isset() is better since it check if the key exists and isn't null.
    if (isset($_POST['send'])) {
        // If you rather put the values in separate variables,
        // you should do it here, inside the if-statement (where we know we
        // got a POST request)
    
        if (!empty($_POST['key'])) {
            echo 'The key you entered is ' . $_POST['key'];
        }
        else {
            echo 'You did not enter a key. Please enter a key into this form field.';
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来