Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Discussion Section / Office Hours Poll Taker

by hossman (Prior)
on Sep 14, 2004 at 05:14 UTC ( #390742=sourcecode: print w/replies, xml ) Need Help??
Category: CGI Programming
Author/Contact Info hossman

This is a CGI for gathering personal info from students, and what times of the day are convinient for them to have Discussion Sections (or Office hours). The DATA section shows an example of what the HTML form that posts to it should look like.

I've also written a script to parse the output into an Excel file


# $Id: class-schedule-form.cgi,v 1.7 2004/08/18 18:31:12 hossman Exp $
# $Source: /home/hossman/cvs_archive/code/perl/class-scheduler/class-s
rm.cgi,v $

use warnings;
use strict;

use Fcntl qw(:flock :seek);
use CGI;

use vars qw($file $thank);
use vars qw($email $fname $lname $sid $status @sections $none);
use vars qw($q @err);
# the file all of our data goes to
$file = "./class-schedule-data.txt";

# the thank you page
$thank = "./thanks.html";

eval {
    $q = new CGI;
    # get our section list, ensure all be numbers
    # (don't bother reporting errors, only comes from spoofers, so fuc
+k them)
    @sections = $q->param('section');
    $_ =~ s/[^\d]//g foreach @sections;
    # get all vals, and strip out colon, and line enders
    ($email  = $q->param('email')  || '') =~ s/:|\n|\r//g;
    ($fname  = $q->param('fname')  || '') =~ s/:|\n|\r//g;
    ($lname  = $q->param('lname')  || '') =~ s/:|\n|\r//g;
    ($sid    = $q->param('sid')    || '') =~ s/:|\n|\r//g;
    ($status = $q->param('status') || '') =~ s/:|\n|\r//g;
    ($none   = $q->param('none')   || '') =~ s/:|\n|\r//g;

    push @err, "You must specify a valid Student ID"
        unless $sid    =~ /^\d+$/;
    push @err, "You must specify your First Name"    unless $fname =~ 
    push @err, "You must specify your Last Name"     unless $lname =~ 
    push @err, "You must specify your Email Address" unless $email =~ 
    push @err, "You must specify your Enrollment Status"
        unless $status =~ /^(W|E|N)$/;
    if (0 == @sections and ! $none) {
        push @err, "You must check the sections you can attend " .
            "or indicate that you can't attend any";
    } elsif (0 < @sections and $none) {
        push @err, "You can not check sections that you can attend " .
            "AND indicate that you can't attend any";
    die "User Input Errors" if @err;

    # lock our file, and write out to it
    open(FILE, ">>$file") or die "couldn't open data file to append";
    flock(FILE, LOCK_EX) or die "can't lock data file";
    seek(FILE, 0, SEEK_END) or die "can't see data file";
    print FILE "$sid:$lname:$fname:$email:$status:",join(" ",@sections
    close FILE;
    print $q->redirect($thank);
if ($@) {
    my $msg = $@;
    push @err, "There was a server problem.  Please contact your GSI."
        unless @err;
        $q->start_html('Something Went Wrong'),
        $q->h2('Something Went Wrong'),
        $q->ul(map { $q->li($_) } @err ),
    die $msg;


<form action="./class-schedule-form.cgi">

SID: <input type="text" name="sid" /></td>
First Name: <input type="text" name="fname" />
Last Name: <input type="text" name="lname" />
Email Address: <input type="text" name="email" />
Enrollment Status:
<select name="status">
  <option value="none" selected>Pick One</option>
  <option value="E">Enrolled</option>
  <option value="W">Waitlisted</option>
  <option value="N">Neither</option>
Sections Available...<br/>
<input type="checkbox" name="section" value="0" /> Mon 10 - 11am<br/>
<input type="checkbox" name="section" value="1" /> Mon 2 - 3pm<br/>
<input type="checkbox" name="section" value="2" /> Mon 3 - 4pm<br/>
<input type="checkbox" name="section" value="3" /> Mon 4 - 5pm<br/>
<input type="checkbox" name="section" value="4" /> Tue 12 - 1pm<br/>
<input type="checkbox" name="section" value="5" /> Tue 1 - 2pm<br/>
<input type="checkbox" name="section" value="6" /> Tue 4 - 5pm<br/>
<input type="checkbox" name="section" value="7" /> Wed 9 - 10am<br/>
<input type="checkbox" name="section" value="8" /> Wed 10 - 11am<br/>
<input type="checkbox" name="section" value="9" /> Thur 12 - 1pm<br/>
<input type="checkbox" name="section" value="10" /> Thur 1 - 2pm<br/>
<input type="checkbox" name="none" value="1" /> I can't make any of th
<input type="submit" value="Submit"/>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://390742]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2021-01-21 18:46 GMT
Find Nodes?
    Voting Booth?