首页 > 解决方案 > PHP FILTER_INPUT 不接收文本输入

问题描述

我在 macOSX 上的 MAMP 上运行 Apache 服务器。我遇到的问题是每个变量都在接收 filter_input() 但最后一个变量是“param”。我试过使用 $_POST['param']; 无济于事。我重新启动了 Apache 服务器,但没有任何改变。我确定这是一个语法错误,但这里的所有其他问题都是不相关且无益的。一个“没有接收输入的 PHP 表单”根本没有帮助。任何帮助表示赞赏:)

编辑:我已经意识到不需要使用 filter_input(INPUT_POST, "param") 因为我没有提供过滤器,并且 $_POST["param"] 是一种更容易接受的方法。

我的 HTML:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Code Writer (JAVA)</title>
</head>
<body>
    <center>
        <h1>Code Writer (JAVA)</h1>
    </center>
    <form action="backwards.php" method="post">
        <fieldset>
            <label>Enter visibility level (public/private/etc)</label>
            <input type="text" name="first"><br>
            <label>Static Method? Y/N</label>
            <input type="text" name="static"><br>
            <label>Enter return type (int/double/etc)</label>
            <input type="text" name="return"><br>
            <label>Enter method name?</label>
            <input type="text" name="method"><br>
            <label>Paramaters, if any</label>
            <input type="text" name="param"><br>
            <button type="submit">Submit</button>
        </fieldset>
    </form>
</body>
</html>

我的PHP:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>backwards.php</title>
</head>
<body>
    <?php
        #Gather inputs
        $first = filter_input(INPUT_POST, "first");
        $static = filter_input(INPUT_POST, "static");
        $return = filter_input(INPUT_POST, "return");
        $method = filter_input(INPUT_POST, "method");
        $param = filter_input(INPUT_POST, "param");

        #Add to $output
        $output = $first . " ";
        if ($static == "Y") {
            $output .= "static" . " ";
        }
        $output .= $return . " ";
        $output .= $method . "(";
        $output .= $param;
        $output .= ") {} \n";

        #Print $output
        print($output);
    ?>
</body>
</html>

标签: php

解决方案


事实证明,在使用@John Conde 的评论“var_dumb($_POST)”运行网站后,它就开始工作了。删除 var_dump 并且它仍然有效,尽管我对为什么感到困惑。问题已解决,但我仍然对为什么它现在有效,而不是以前有效。


推荐阅读