欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php中的html元素

程序员文章站 2022-05-17 17:56:43
...

我们先看下面的代码 form2.php html head title greetins eartyling / title / head body form action ="formprocess2.php" method ="post" table tr td Name / td td input type ="text" name ="name" // td / tr tr td Greetings / td td select name ="gr

我们先看下面的代码

form2.php

html> 
head>title>greetins eartylingtitle>head>
body> 
form action="formprocess2.php" method="post">
    table>
        tr>
            td>Nametd>
            td>input type="text" name="name" />td>
        tr>
        tr>
            td>Greetingstd>
            td>
                select name="greeting" id="">
                    option value="Hello">Hellooption>
                    option value="Hola">Holaoption>
                    option value="Bonjour">Bonjouroption>
                select>
            td>
        tr>
        tr>
            td> td>
            td>input type="checkbox" name="debug" checked="checked"/>Display Debug infotd>
        tr>
        tr>
            td colspan="2" style="text-align:center">
                input type="submit" name="submit" value="Submit"/>
            td>
        tr>
    table>
form>
body>
html>

formprocess2.php

html>
    head>
        title>Greeting earthingtitle>
    head>
    body>
    php
    echo '

'.$_POST["greeting"] ." ".$_POST["name"].' !

'; if(isset($_POST["debug"])) { echo '
Degut:';
        print_r($_POST);
        echo '
'; }
?> body> html>

选中Display Debug info这个checkbox然后点击submit显示内容如下:

Bonjour 谁谁谁 !

Degut:Array
(
    [name] => 谁谁谁
    [greeting] => Bonjour
    [debug] => on
    [submit] => Submit
)

可以看到input元素的值都可以使用$_POST("name")函数来获得,不单单是文本框,单选框checkbox和下拉列表框select都可以,注意这里checkbox如果选中获取的值是"on",不是true,还有如果我们没有选中checkbox使用$_POST("debug")来获取这个checkbox的值会报错,因为$_POST这个数组中没有这个元素。