include("../../admin/config.php"); // Make sure we're dealing with the UTF-8 charset mysql_query("SET NAMES 'utf8'"); header('Content-Type: text/html; charset=utf-8'); //$reg_id = uniqid(""); //$_POST['reg_id'] = $reg_id; $errors = array(); $errormsg = ''; $edit = array(); // a list of all the fields, to retrive from POST $allfields = array('f_name', 'l_name', 'region', 'address1', 'address2', 'address3', 'city', 'state', 'zip', 'country', 'phone', 'email', 'school', 'schooladdress1', 'schooladdress2', 'schooladdress3', 'schoolcity', 'schoolstate', 'schoolzip', 'schoolcountry', 'major', 'graduationdate', 'teachername', 'teacheremail', 'teacherphone', 'group_register', 'group_members', 'heardfrom', 'heard_from_other' ); if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') { foreach($allfields as $key) { if(!empty($_POST[$key])) $edit[$key] = stripslashes($_POST[$key]); } // used to check for errors and missing fields // fieldname => default value (the default value counts as a missing field) $requiredfields = array('f_name' => 'FIRST NAME', 'l_name' => 'LAST NAME', 'region' => '', 'address1' => 'ADDRESS 1', 'city' => 'CITY', 'state' => 'STATE/PROVINCE', 'zip' => 'ZIP/POST CODE', 'country' => '', 'phone' => 'PHONE NUMBER', 'email' => 'EMAIL ADDRESS', 'school' => 'SCHOOL', 'schooladdress1' => 'ADDRESS 1', 'schoolcity' => 'CITY', 'schoolstate' => 'STATE/PROVINCE', 'schoolzip' => 'ZIP/POST CODE', 'schoolcountry' => '', 'heardfrom' => '' ); // plain english names of the required fields -- for error messages $requirednames = array('f_name' => 'First Name', 'l_name' => 'Last Name', 'region' => 'Region', 'address1' => 'Address 1', 'city' => 'City', 'state' => 'State/Province', 'zip' => 'Zip/Post Code', 'country' => 'Country', 'phone' => 'Phone Number', 'email' => 'Email Address', 'school' => 'School', 'schooladdress1' => 'School Address 1', 'schoolcity' => 'School City', 'schoolstate' => 'School State/Province', 'schoolzip' => 'School Zip/Post Code', 'schoolcountry' => 'School Country', 'heardfrom' => 'How did you hear about the contest?' ); // to check for email addresses $emailpattern = '^(mailto:)?[-!#$%&\'*+\\./0-9A-Z^_`a-z{|}~]+'. '@'. '([-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.)+' . '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+$'; // check for required fields foreach($requiredfields as $f => $val) { if(!isset($_POST[$f]) || $_POST[$f] == $val) { $errors[] = 'Please enter: '.$requirednames[$f]; } else { if($f == 'heardfrom' && $val == 'other' && $_POST['heard_from_other'] == '') $errors[] = 'Please tell us how you heard about the contest.'; } } // valid email if(isset($_POST['email']) && $_POST['email'] != 'EMAIL ADDRESS' && !ereg($emailpattern, stripslashes($_POST['email']))) { $errors[] = 'Please enter a valid email address (only one please).'; } else { $matches = array(); // the there's a mailto:, remove it if(preg_match('/^mailto:(.+)/', $_POST['email'], $matches)) { $edit['email'] = $matches[1]; $_POST['email'] = $matches[1]; } } // valid teacher email if(isset($_POST['teacheremail']) && ($_POST['teacheremail'] != 'TEACHER EMAIL ADDRESS' && $_POST['teacheremail'] != '') && !ereg($emailpattern, stripslashes($_POST['teacheremail']))) { $errors[] = 'Please enter a valid teacher\'s email address (only one please).'; } else { $matches = array(); // if there's a mailto:, remove it if(preg_match('/^mailto:(.+)/', $_POST['teacheremail'], $matches)) $edit['teacheremail'] = $matches[1]; } // reformat the graduation date from MM-DD-YYYY to the system-accepted YYYY-MM-DD if(isset($_POST['graduationdate']) && ($_POST['graduationdate'] != 'GRADUATION DATE' && $_POST['graduationdate'] != '')) { $graddate = stripslashes($_POST['graduationdate']); $gradpattern = '/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/'; $gooddate = false; if(preg_match('/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/', $graddate)) { $newdate = $graddate; $gooddate = true; } else if(preg_match('/^([0-9]{2})-([0-9]{2})-([0-9]{2})$/', $graddate, $matches)) { $newdate = $matches[1].'-'.$matches[2].'-20'.$matches[3]; $gooddate = true; } else if(preg_match('/^([0-9]{1,2})[-\/\. ]([0-9]{1,2})[-\/\. ]([0-9]{2,4})$/', $graddate, $matches)) { $newdate = ($matches[1] < 10 ? '0'.($matches[1]%10) : $matches[1]).'-'.($matches[2] < 10 ? '0'.($matches[2]%10) : $matches[2]).'-20'.($matches[3]%100 < 10 ? '0'.$matches[3]%100 : $matches[3]%100); $gooddate = true; } else { $newdate = $graddate; } if($gooddate) { $_POST['graduationdate'] = $newdate; $edit['graduationdate'] = $newdate; } else { $errors[] = 'Please enter your graduation date in MM-DD-YYYY format.'; } } // if there are no errors, put together the query string and submit it if(count($errors) == 0) { $defaults = array('f_name' => 'FIRST NAME', 'l_name' => 'LAST NAME', 'address1' => 'ADDRESS 1', 'address2' => 'ADDRESS 2', 'address3' => 'ADDRESS 3', 'city' => 'CITY', 'state' => 'STATE/PROVINCE', 'zip' => 'ZIP/POST CODE', 'phone' => 'PHONE NUMBER', 'email' => 'EMAIL ADDRESS', 'school' => 'SCHOOL', 'schooladdress1' => 'ADDRESS 1', 'schooladdress2' => 'ADDRESS 2', 'schooladdress3' => 'ADDRESS 3', 'schoolcity' => 'CITY', 'schoolstate' => 'STATE/PROVINCE', 'schoolzip' => 'ZIP/POST CODE', 'major' => 'MAJOR', 'graduationdate' => 'GRADUATION DATE', 'teachername' => 'TEACHER NAME', 'teacheremail' => 'TEACHER EMAIL ADDRESS', 'teacherphone' => 'TEACHER TELEPHONE', ); $querystring = ''; foreach($_POST as $key => $value) { if(isset($defaults[$key]) && $value == $defaults[$key]) $value = ''; if($key != 'submit') $querystring .= ", $key = '".mysql_escape_string($value)."'"; } $querystring = "insert into registration set registration_date = now() , ".substr($querystring,1); //$querystring = "insert into registration set ".substr($querystring,1); mysql_query($querystring); // die($querystring); $id = mysql_insert_id(); $reg_id = $_POST['region'].$id; // if the registration succeceded, update the reg_id and forward them to the thanks page if($id) { $query = "update registration set reg_id='$reg_id' where id='$id'"; mysql_query($query); header("Location: regthanks.html?reg_id=$reg_id"); } else { // if reg failed, send email to sean $errormsg = '
| include("../../includes/nav.php"); ?> |
include("sidebar.php");
?>
Deadline for Registration: See
chart for your region or country. Note: China students cannot register using this form. To register in the Chinese round, please visit
DAFChina.com.
Your unique registration number will be generated upon completion of this form. Please make a note of this number for your records. Fields marked with a * are required. include("dafend.php"); ?> |