繁体   English   中英

HTML表单中输入标签中的隐藏属性

[英]hidden attribute in input tag from html form

我正在尝试获取发布的信息并使用以下代码显示信息:

PHP代码:

        $self = $_SERVER['PHP_SELF'];
        if(isset($_POST['send'])){                
            $words = htmlspecialchars($_POST['board']);
            print "<b>".$words."</b>";
        }            ​​​​

HTML代码

<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
        <p><i>Comment</i></p>
        <textarea name="board" rows="20" cols="10"></textarea>
        <input name="send" type="hidden" />
        <p><input type='submit' value='send' /></p>
</form>  

上面的代码将按我的意图工作。 但是,如果我放弃了输入名称=“发送”,类型=“隐藏”,则单击发送按钮后将不会显示用户输入消息。 为什么会这样?

您需要在提交按钮上添加name ='send',PHP代码正在读取表单元素的名称,并且您尚未为提交按钮指定一个。

<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
        <p><i>Comment</i></p>
        <textarea name="board" rows="20" cols="10"></textarea>
        <p><input type='submit' name='send' value='send' /></p>
</form>  

另外,请注意-您可以将表单方法更改为GET而不是POST,以轻松查看要在URL栏中发送的表单数据。

这是因为您正在检查是否已设置POST变量“发送”。 那就是您命名隐藏输入的名称。

您应该在提交输入中添加一个name 例:

    <p><input type='submit' name="submit_button" value='send' /></p>

现在在您的php中,检查您的提交按钮的name 在此示例中,我使用了“ submit_button”。 这是修改后的代码示例:

    $self = $_SERVER['PHP_SELF'];
    if(isset($_POST['submit_button'])){                
        $words = htmlspecialchars($_POST['board']);
        print "<b>".$words."</b>";
    }  

不必麻烦命名发送按钮或其他任何东西,只需删除该hidden线即可。

并将您的php更改为...。

 $self = $_SERVER['PHP_SELF'];
    if(isset($_POST)){                
        $words = htmlspecialchars($_POST['board']);
        print "<b>".$words."</b>";
    }     

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM