Form Generator
PHP Code Examples
<?php include '../'; 
      include ''; 

// Figure out the URL of the processing script.
$proc = preg_replace('@/[^/]+$@', "/surread.php", $_SERVER["SCRIPT_NAME"]);

// First line of file is name of survey.  Read it, then start generating
// HTML for the survey form.
$surid = substr($_SERVER['PATH_INFO'], 1);
$surdef = open_sur($surid);
$title = fgets($surdef, 40);
echo <<<END
We would appreciate if you would be willing to fill
out our survey.  It will only take a few minutes of your time.<p>
<b>Many Thanks!</b><p>
<form action="$proc" method="post">
<input type="hidden" name="surv_path_info" value="$surid">

// One line per question, separated by ':'.  Generate each question
// as a line in a table.  
$qno = 1;  // Question numbers.
while(! feof($surdef)) {
	// Get the line and split it into parts.
	$line = fgets($surdef, 1024);
	$parts = explode(':', $line);

	// Generate the question.
	$ques = htmlspecialchars(array_shift($parts));
	echo "<tr align=\"left\" valign=\"top\"><td>$ques</td>";

	// Generate the response alternatives.
	$rno = 1;
	echo "<td align=\"left\" valign=\"top\">";
	foreach($parts as $resp) {
		$resp = htmlspecialchars($resp);
		$resp = preg_replace('/ /', '&nbsp;', $resp);
		if($rno > 1) echo "&nbsp;&nbsp;&nbsp;&nbsp;\n";
		echo "<nobr><input type=\"radio\" name=\"ques_$qno\" ",
	echo "</td></tr>\n";

// Close the HTML stuff, and generate submit and clear buttons.
echo <<<END
	<br><input type="submit" name="submit" value="Submit Survey">
	<input type="reset" value="Clear Survey">