The field \"$fieldName\" is required.\n"; ++$errorCount; $retval = ""; } else //Only clean up the input if it isn't empty { $data = trim($data); $data = stripslashes($data); if (is_numeric($data)) { $data = round($data); $currentYear = date("Y"); // Debug // echo $currentYear; //if ($data == date("Y") || ($data == date("Y") + 1) || ($data == date("Y") + 2)) if ($data >= $currentYear && $data <= $currentYear+2) { $retval = $data; } else { $errorMessage .= "

The field $fieldName must be between the Current Year or at most 2 years in the Future.

\n"; ++$errorCount; $retval = ""; } } else { $errorMessage .= "

The field $fieldName must be a NUMBER between the Current Year or at most 2 years in the Future.

\n"; ++$errorCount; $retval = ""; } } return ($retval); } function validatePhoneNumber($data, $fieldName) { global $errorMessage; global $errorCount; if (empty($data)) { $errorMessage .= "

The field \"$fieldName\" is required.

\n"; ++$errorCount; $retval = ""; } else //Only clean up the input if it isn't empty { $data = trim($data); $data = stripslashes($data); $pattern = "/\d{3}-\d{3}-\d{4}/"; if (preg_match($pattern, $data)) { $retval = $data; } else { $errorMessage.= "

The field $fieldName must be a telephone number in the form ###-###-####.

\n"; ++$errorCount; $retval = ""; } } return($retval); } function redisplayForm($firstName, $lastName, $telephoneNumber, $year) { ?>

Please, enter your name, graduation year, and telephone number in the form below. We will contact you soon regarding a potential scholarship. Thank you.

First Name:

Last Name:

Telephone Number:

Year:

  

The field \"$fieldName\" is required. \n"; } function validateInput($data, $fieldName) { global $errorCount; if (empty($data)) { displayRequired($fieldName); ++$errorCount; $retval = ""; } else //Only clean up the input if it isn't empty { $retval = trim($data); $retval = stripslashes($retval); } return($retval); } $errorCount = 0; $firstName = validateInput($_POST['fName'], "First name"); $lastName = validateInput($_POST['lName'], "Last name"); $telephoneNumber = validatePhoneNumber($_POST['tNumber'], "Telephone Number"); $year = validateYear($_POST['year'], "Year"); if ($errorCount > 0) { $errorMessage .= "

Please re-enter the information below.

\n"; redisplayForm($firstName, $lastName, $telephoneNumber, $year); } else { echo "
"; echo "

Thank you for filling out the scholarship form, " . $firstName . " " . $lastName . " .

"; echo "

Your phone number was entered as $telephoneNumber.

"; echo "

The year you are applying is $year.

"; echo "
"; //print_r($_POST); } echo $errorMessage; ?>