Home > php教程 > php手册 > 利用表单调查表实例

利用表单调查表实例

WBOY
Release: 2016-05-25 16:46:00
Original
1021 people have browsed it

<html>  
<head> 
<title>php教程入门教程:利用表单调查表实例</title> 
<meta http-equiv="content-type" content="text/html; charset=gb2312"> 
</head> 
<body bgcolor="#ffffff"> 
<?php
// 定义显示表单函数
function display_form() {
    global $php_self;
?>
<form action="<?php
    echo $php_self; ?>"method=post> 
名字: <input type=text name="name"><br> 
单项选择:  
<input type=radio name="first" value="我很笨">我很聪明 
<input type=radio name="first" value="我非常笨">我很笨 
<input type=radio name="first" value="我简直就是个傻冒"> 我简直就是个傻冒 <br> 
 
多项选择:  
<input type=checkbox name="second[]" value="我喜欢打蓝球">我喜欢打蓝球 
<input type=checkbox name="second[]" value="我喜欢游泳">我喜欢游泳 
<input type=checkbox name="second[]" value="我喜欢跳舞">我喜欢跳舞 
<input type=checkbox name="second[]" value="我喜欢爬山">我喜欢爬山 
<input type=hidden name="stage" value= "results"><p> 
<input type=submit value= "谢谢"></p> 
</form> 
<?php
}
?>
//程序开始 
<?php
// 定义处理表单函数
function process_form() {
    global $name;
    global $first;
    global $second;
    if ($first == &#39;我很笨&#39;) {
        $first_message = &#39;你不笨。&#39;;
    } elseif ($first == &#39;我很聪明&#39;) {
        $first_message = &#39;你不聪明。&#39;;
    } else {
        $first_message = &#39;你简直就象是一个聪明的人了。&#39;;
    }
    $favorite_second = count($second);
    if ($favorite_second <= 1) {
        $second_message = &#39;但你做错事了,忏悔吧!&#39;;
    } elseif ($favorite_second > 1 && $favorite_second < 4) {
        $second_message = &#39;你是只爱运动的的猩猩。&#39;;
    } else {
        $second_message = &#39;你运动的太多了,对猩猩来讲已经过量:(&#39;;
    }
    echo "这是一项针对猩猩的测试:<br><br>";
    echo "你好! 你的名字叫:$name. <br><br>";
    echo "你的测验结果是。。。。。$first_message $second_message";
}
?>
<?php
if (emptyempty($stage)) {
    display_form();
} else {
    process_form();
}
?>
</body>  
</html>
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template