32.3 解决方案概述

在这个项目中,我们将设计一个具有3种可能输出的系统。如图32-1所示,我们将提出测验问题,评估用户的回答,然后用以下3种方法之一来生成证书:

■用一个空白模板生成RTF文档。

■用一个空白模板生成PDF文档。

■通过PDFlib库用程序生成PDF文档。

32.3.1 提问 - 图1

图 32-1 证书系统将生成3种不同证书中的一种

表32-1给出了该证书项目将用到的所有文件。

32.3.1 提问 - 图2

下面,我们继续学习该程序。

32.3.1 提问

index.html文件非常直观。它必须包含一个HTML表单来询问用户姓名及一些问题的答案。在一个真正的评估应用程序中,很可能是从数据库中取出这些问题。在这里,我们将集中讨论产生证书的问题,因此只随意编造几个题目“硬编码”在HTML中。

姓名域是一个文本输入框。每个题目有3个单选按钮以供用户选择答案。该表单还有一个带有图像的提交按钮。

该页的代码如程序清单32-1所示。

程序清单32-1 index.html——包含测验问题的HTML页


<html>

<body>

<h1><p align="center">

<img src="rosette.gif"alt="">

Certification

<img src="rosette.gif"alt=""></p></h1>

<p>You too can earn your highly respected PHP certification

from the world famous Fictional Institute of PHP Certification.</p>

<p>Simply answer the questions below:</p>

<form action="score.php"method="post">

<p>Your Name<input type="text"name="name"/></p>

<p>What does the PHP statement echo do?</p>

<ol>

<li><input type="radio"name="q1"value="1"/>

Outputs strings.</li>

<li><input type="radio"name="q1"value="2"/>

Adds two numbers together.</li>

<li><input type="radio"name="q1"value="3"/>

Creates a magical elf to finish writing your code.</li>

</ol>

<p>What does the PHP function cos()do?</p>

<ol>

<li><input type="radio"name="q2"value="1"/>

Calculates a cosine in radians.</li>

<li><input type="radio"name="q2"value="2"/>

Calculates a tangent in radians.</li>

<li><input type="radio"name="q2"value="3"/>

It is not a PHP function.It is a lettuce.</li>

</ol>

<p>What does the PHP function mail()do?</p>

<ol>

<li><input type="radio"name="q3"value="1"/>

Sends a mail message.

<li><input type="radio"name="q3"value="2"/>

Checks for new mail.

<li><input type="radio"name="q3"value="3"/>

Toggles PHP between male and female mode.

</ol>

<p align="center"><input type="image"src="certify-me.gif"border="0"></p>

</form>

</body>

</html>


如图32-2所示的是在浏览器中打开index.html的结果。

32.3.1 提问 - 图3

图 32-2 index.html要求用户回答测试问题