vertigo Veteran 135 Posts user info edit post |
I currently volunteer for a non-profit food kitchen-type organization where different organizations (whether religious or non-affiliated humanitarian groups) sign up for specific days to provide labor and foodstuff. This is a fairly large program and it works fairly well, though the sign-up process is a bit of a hassle. Currently, groups have to call in or send an email to a part-time volunteer secretary that has to manually record who will be there and on which days. I thought it would be a good idea and a relatively simple undertaking to set up an online form that will keep her from having to keep track of everyone. I know VERY basic PHP (like includes and some built-in functions) and, for some reason, though I could figure this out on my own. But I'm getting very frustrated and any help that you could provide would be much appreciated. This might be too much of a project and maybe I'm asking for too much, but I didn't think it would hurt to ask, especially since it's for a good cause. Really, any suggestions would be appreciated.
Okay, so there are 6 fields - date (preferably in yyyy-mm-dd format), first name of contact (20 characters max), last name of contact (25 characters max), email address (30 characters max), group ID number (4-digit number assigned by our organization to each individual group), and a phone number (preferably in the 123-456-7890 format). The HTML form (signup.html) looks like this:
<form id="signup" action="signup_form.php" method="post"> <ul> <li><select name="date"> <option value="20080101">January 1, 2008</option> <option value="20080102">January 2, 2008</option> <option value="20080103">January 3, 2008</option> </select></li> <li>First Name: <input type="text" size="20" name="fname" /></li> <li>Last Name: <input type="text" size="25" name="lname" /></li> <li>Email: <input type="text" size="30" name="email" /></li> <li>Group ID: <input type="text" size="4" name="group" /></li> <li>Phone: <input type="text" size="12" name="phone" /></li> <li><input class="button" type="submit" value="submit" /><input class="button" type="reset" value="reset" /></li> </ul> </form>
For each day, there are 3 sign-up spots (one for each meal) and an alternate in case a group has to cancel. Once the day is full, or after the date has passed, I'd love for the option to disappear from the list, but that might be more work than it's worth (I can manually add/remove these dates since it's not that time intensive and even I can handle it). After someone submits, I'd like for an email to be sent to the secretary that just lets her know that someone has signed up for a specific date. Also, I'd like the ability to print off the sheet for a single day, as well as the option to print off a full list (I mean, after all days are full, she'd be able to print off the full list and hang it on the bulletin board). Here's what I currently have for the database part (signup_form.php):
<?php
# connecting to MySQL database with default settings, storing as a variable # # die is executed if the connection fails # $fpDB = mysql_connect(); if (!$fpDB) { die("Could not connect to database: " . mysql_error()); }
# creating the database, returning status # if (mysql_query("CREATE DATABASE foodpantry_db",$fpDB)) { echo "Database created."; } else { echo "Error creating database: " . mysql_error(); }
# generating the table and fields within the database # # setting primary key field, cannot be null # mysql_select_db("foodpantry_db",$fpDB); $sql = "CREATE TABLE group_signup ( foodpantry_dbID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(foodpantry_dbID), VolDate date(yyyy-mm-dd), FirstName varchar(20), LastName varchar(25), EmailAddy varchar(30), GroupID int(4), ContactNum varchar(12))"; mysql_query($sql,$fpDB);
# inserting values from form into the table # $sql = "INSERT INTO group_signup (VolDate,FirstName,LastName,EmailAddy,GroupID,ContactNum) VALUES('$_POST[date]','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[group]','$_POST[phone]')"; if(!mysql_query($sql,$fpDB)) { die("Error: " . mysql_error()); } echo "1 record added.";
# closing the MySQL connection # mysql_close($fpDB);
?>
For the emailing portion (which I've tried separately using just a form, with no database, and it works), I've got:
<?php
# begin output buffering to handle headers # ob_start();
# prevents values from being entered in an URL # if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}
# assign recipient email, subject, thank you and empty fields pages # $sendto = 'myname@mysite.com'; $subject = 'Food Pantry Signup Form'; $thankyou = 'signup_reply.html'; $req_fields = 'req_fields.html'; $valid_email = 'valid_email.html';
# creates variables from form inputs # $fname = $_REQUEST['fname']; $lname = $_REQUEST['lname']; $email = $_REQUEST['email']; $group = $_REQUEST['group'];
# if the field contains data, compiles form variables into one - empty fields are omitted # if (strcmp($fname, "")!=0) $body = $fname." "; if (strcmp($lname, "")!=0) $body = $lname."\n"; if (strcmp($email, "")!=0) $body .= "Email: ".$email."\n"; if (strcmp($group, "")!=0) $body .= "Group ID: ".$group;
# assigns values to the email's header information (from, reply-to, etc.) # $headers = "From: ".$email."\n";
# checks to make sure all fields are filled (all are required) # if(empty($name) || empty($email) || empty($group)) { header("location:$req_fields"); }
# checks to make sure there is a valid email address entered # elseif((!$email == "") && (!strstr($email,"@") || !strstr($email,"."))) { header("location:$valid_email"); }
# composes the email, redirects user to a thank you page after submission # else { mail($sendto, $subject, $body, $headers); header("location:$thankyou"); }
# end output buffering # ob_end_flush();
?>
I think maybe I'm asking for too much. It's just a lot more than I thought it would be, and I'm sort of piecing it together using various tutorials. I do have a server with MySQL to test it, but I know it's not complete. Again, any help you can provide would be appreciated. Even if your only suggestion is to get a professional to do it, I'd appreciate your viewpoint. Thanks!
[Edited on December 17, 2007 at 4:22 PM. Reason : I've pulled this from a number of different samples, so if something seems out of whack, let me know] 12/17/2007 4:18:40 PM |