<html xmlns="http://www.w3.org/1999/xhtml">
       <head>
       <title>Scholarship Form</title>
       <meta http-equiv="content-type"
            content="text/html; charset=iso-8859-1" />
       </head>
       <body>
       <?php 
// Strip slashes allows for quotations
// Example John O'Hara
$firstName = validateInput($_POST['fName'], "First name");
$lastName = validateInput($_POST['lName'], "Last name");
// Will either display total number of errors or Thank You Message
if ($errorCount > 0) {
    echo "Please re-enter the information below.<br />";
    redisplayForm($firstName, $lastName);
} else {
    //      echo "Thank you for filling out the scholarship form,
    //            ".$firstName." ".$lastName . ".";
    // Send an e-mail instead of display message above
    $To = "*****@*****.**";
}
$Subject = "Scholarship Form Results";
$Message = "Student Name: " . $firstName . " " . $lastName;
$result = mail($To, $Subject, $Message);
if ($result) {
    $resultMsg = "Your message was successfuly sent.";
} else {
    $resultMsg = "There was a problem sending your message.";
}
// displayRequired() Accepts one argument, $fieldName
示例#2
0
// Redisplays forms if errors are present
if ($errors > 0) {
    echo "Please re-enter the information below.<br />";
}
// Calculate paycheck under 40 hours
if ($hourWorked <= 40) {
    $paycheck = $hourWorked * $hourWage;
    redisplayForm($hourWorked, $hourWage);
    echo "<strong>Your paycheck is: \${$paycheck}.<br /></strong>";
}
// Calculate paycheck over 40 hours
if ($hourWorked > 40) {
    $oHour = $hourWorked - 40;
    $oWage = $hourWage * 1.5;
    $paycheck = 40 * $hourWage + $oHour * $oWage;
    redisplayForm($hourWorked, $hourWage);
    echo "<strong>Your paycheck is: \${$paycheck}.<br /></strong>";
}
// Input checks if blank and if input is a number
function inputCheck($data, $fieldName)
{
    global $errors;
    if (empty($data)) {
        fieldRequired($fieldName);
        ++$errors;
        $retval = "";
    }
    if (ctype_alpha($data)) {
        numRequired($fieldName);
        ++$errors;
        $retval = "";