Course Feedback Tool
Posted by rutang5 on October 19, 2006
The purpose of this post is twofold: first, I want to test out this new code formatting plugin I downloaded, and second, I wanted to share my anonymous course feedback tool with anyone else who wants to adapt it for their own Web site. You can see the end result on my own Web site.
I’m posting this primarily for my friend Jon, who wanted to do something similiar on his site. I says to him, I says, “Hey, Jon, why reinvent the wheel, man? Just use my code and modify it to fit your needs.” And he says, “Yeah man. Cool.”
Note: You’ll need to have the GD Image Library enabled on your PHP server for this to work. Otherwise, you’ll need to come up with an alternate method to authenticate for human-ish users.
You can download the source files from this link.
File 1: feedback.php (main file to display the feedback tool)
<?php $prof_email = ""; // plug in your email address here $server = ""; // plug in your server name here ?> <html> <head> <title>Course Feedback Tool</title> </head> <body> <h1>Anonymous Feedback Tool</h1> <p>Reasons you may want to use this tool:</p> <ul> <li>To request a special lecture topic <li>To ask a question you didn't want to ask in class <li>To give me feedback about a particular course <li>To gripe or complain about a lecture <li>To comment on an especially good or helpful lecture <li>To provide a review for one of my courses <li>To provide ideas for activities or outside readings <li>You get the point, right? </ul> <?php if (isset($_POST["submit"])) { $usercode = trim($_POST["user-code"]); $passcode = trim($_POST["system-code"]); if ($usercode == $passcode) { $message = "Nature of Feedback: ". $_POST["nature"]."nnCourse: ". $_POST["course"]."nn". $_POST["comments"]; mail($prof_email,"feedback from Web site",$message) or die($server." mail appears to be down. Please let me know ASAP!"); ?> <hr> <span class="font-weight: bold"> Thank you for your feedback! I appreciate all comments.</span> <?php } else { ?> <hr> <span class="font-weight: bold"> Sorry. Your user code did not match the verification code. Please go back and try again.</span> <?php } } else { ?> <hr> <span class="font-weight: bold">Please complete the form below.</span> <form id="feedback" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <table> <tr> <td>Nature of Feedback:</td> <td colspan="2"> <select name="nature"> <option>Suggestion for Lecture Topic</option> <option>Feedback Concerning Lecture</option> <option>Feedback Concerning Class Activity</option> <option>General Classroom Issue</option> <option>Review of Class</option> <option>Feedback Concerning Web site</option> <option>Resource Suggestion for Web site</option> <option>Other</option> </select> </td> </tr> <tr> <td>Course:</td> <td colspan="2"> <select name="course"> <option>DIG3930: ST: Rapid App Web Development</option> <option>DIG4716: Internet Interaction</option> <option>DIG4922: Media for E-Commerce II</option> <option>DIG5647: Sci and Tech of Dynamic Media</option> <option>IDS3701: Internet Software Design</option> <option>Not Course Related</option> <option>Other</option> </select> </td> </tr> <tr> <td valign="top">Comments:</td> <td colspan="2"> <textarea name="comments" rows="5" cols="35"></textarea> </td> </tr> <?php $str = "ABCDEFHJKMNPQRTWXYZabcdefhkmnrtwxz234789"; // removed confusing characters $codelen = 4; $code = ""; for ($i=0; $i < $codelen; $i++) { $num = rand(0,strlen($str)-1); $code .= $str[$num]; } ?> <tr> <td>Verify-Code:</td> <td> <input type="text" name="user-code" size="5" maxlength="4"> </td> <td align="left"> <img src="makecode.php?code=<?php echo $code; ?>" style="border: thin solid black"> </td> </tr> </table> <p>Please copy the <b>case-sensitive</b> four digit code from the right into the area to the left to verify you are a human. If you would like to leave your name or contact details, you can provide it in the comments area.</p> <br> <input type="hidden" name="system-code" value="<?php echo $code; ?>"> <input type="submit" value="Submit Anonymous Feedback" name="submit"> </form> </body> </html>
File 2: makecode.php (used to generate the authentication image code to keep out annoying spam).
1 <?php 2 header ("Content-type: image/png"); 3 $img_handle = ImageCreate (65, 20) or die ("Cannot Create image"); 4 $back_color = ImageColorAllocate ($img_handle, 255, 255, 255); 5 $txt_color = ImageColorAllocate ($img_handle, 0, 0, 0); 6 ImageString ($img_handle, 40, 5, 5, $_GET["code"], $txt_color); 7 ImagePng ($img_handle); 8 ?>
Enjoy, Jon!
