function validate_presence($required_field)
{
    global $errors;
    $value = trim($_POST[$required_field]);
    if (!has_presence($value)) {
        $errors[$required_field] = fieldname_as_text($required_field) . " can't be blank!";
    }
}
Beispiel #2
0
function validate_fields($fields)
{
    global $errors;
    if (!has_presence($fields["email"])) {
        $errors[] = "Email can't be blank";
    }
    if (!has_presence($fields["password"]) && !isset($_SESSION['id'])) {
        $errors[] = "Password can't be blank";
    }
    if (has_presence($fields["password"]) && $fields["confirm_password"] !== $fields["password"]) {
        $errors[] = "Confirm Password Has To be Identical to Password";
    }
    if (has_presence($fields["email"])) {
        $current_user = "";
        $result = find_user_by_email($fields["email"]);
        $user = mysqli_fetch_row($result);
        if (isset($_SESSION['id'])) {
            $current_user = mysqli_fetch_row(find_user_by_id($_SESSION['id']));
        }
        if ($user && $user !== $current_user) {
            // email is the 4th column in table user
            $errors[] = "Email Already Exists";
        }
    }
    // user regex to check email validity
}
Beispiel #3
0
function validat_presence($required_fields)
{
    global $errors;
    foreach ($required_fields as $field) {
        if (!has_presence($field)) {
            $errors[$field] = ucfirst($field) . "can't be blank";
        }
    }
}
Beispiel #4
0
function validate_presence_on($required_fields)
{
    global $errors;
    foreach ($required_fields as $field) {
        if (!has_presence($_POST[$field])) {
            $errors[$field] = "'" . "' can't be blank";
        }
    }
}
Beispiel #5
0
function all_prestnt($name_fields_presence)
{
    global $errors;
    foreach ($name_fields_presence as $field) {
        $value = trim($_POST[$field]);
        if (!has_presence($value)) {
            $errors[$field] = ucfirst($field) . " cannot be blank ";
        }
    }
}
function validate_presences($input_text)
{
    global $errors;
    foreach ($input_text as $field) {
        // $value = trim($_POST[$field]);
        if (!has_presence($_POST[$field])) {
            $errors[$field] = fieldname_as_text($field) . " can't be blank";
        }
    }
}
function validate_presences($required_fields)
{
    global $errors;
    foreach ($required_fields as $field) {
        $value = trim($_POST[$field]);
        if (!has_presence($value)) {
            $errors[$field] = fieldname_as_text($field) . "  can't be blank";
        }
    }
}
function validate_presences_general($required_fields, $array)
{
    global $errors;
    $result = 1;
    foreach ($required_fields as $field) {
        $value = trim($array[$field]);
        if (!has_presence($value)) {
            $errors[$field] = fieldname_as_text($field) . " can't be blank";
            $result = 0;
        }
    }
    return $result;
}
function validate_presences($required_fields)
{
    global $errors;
    foreach ($required_fields as $field) {
        if ($field == 'visible') {
            if (!isset($_POST['visible'])) {
                $errors['visible'] = "visible can't be unchecked";
            }
        } else {
            $value = trim($_POST[$field]);
            if (!has_presence($value)) {
                $errors[$field] = fieldname_as_text($field) . " can't be blank";
            }
        }
    }
}
 if (!has_max_length($greeting, 500)) {
     $errors['greeting'] = "Please limit your greeting to 500 characters.";
 }
 if (!has_presence($friendfirst)) {
     $errors['friendfirst_blank'] = "Please provide your friend's name.";
 }
 if (!has_presence($toemail)) {
     $errors['toemail_blank'] = "Please provide your friend's email address.";
 }
 if (!has_presence($firstname)) {
     $errors['firstname_blank'] = "Please provide your first name.";
 }
 if (!has_presence($fromemail)) {
     $errors['fromemail_blank'] = "Please provide your email address.";
 }
 if (!has_presence($image)) {
     $errors['image_blank'] = "Please select an image for your E-Card.";
 }
 // Error message (could print here, but do it lower down instead)
 // print form_errors($errors);
 // No Errors
 if (empty($errors)) {
     // Select image file & credit text
     $html_image = $image_file[$pos];
     $html_credit = $image_credit[$pos];
     // BUILD EMAIL
     $html_email = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
     $html_email .= "<html>\n";
     $html_email .= "<head>\n";
     $html_email .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
     $html_email .= "<title>Harvard Library Holiday Card from " . $firstname . "</title>\n";
         $user_email = htmlspecialchars($_POST['user_email']);
         $user_data['user_email'] = $user_email;
     } else {
         $user_email = htmlspecialchars($_POST['user_email']);
         $errors[] = "Please enter a valid email address";
     }
 } else {
     $user_email = "";
     $errors[] = "Please enter an email address";
 }
 // check for presence of a password
 if (has_presence($_POST['user_password'])) {
     // make sure its at least 7 characters long
     if (has_min_length($_POST['user_password'], 7)) {
         // check for presence of a conf_password
         if (has_presence($_POST['conf_password'])) {
             // compare the two password for exactness
             if (is_exact($_POST['user_password'], $_POST['conf_password'])) {
                 // passwords match
                 $user_password = htmlspecialchars($_POST['conf_password']);
                 $conf_password = htmlspecialchars($_POST['conf_password']);
                 // hash protect password
                 $hash_password = password_hash($user_password, PASSWORD_DEFAULT);
                 $user_data['user_password'] = $hash_password;
             } else {
                 $user_password = "";
                 $conf_password = "";
                 $errors[] = "Your passwords didn't match";
             }
         } else {
             $user_password = htmlspecialchars($_POST['user_password']);
require_once "../includes/sessions.php";
require_once "../includes/functions.php";
require_once "../includes/validation-functions.php";
require_once "../includes/db-connection.php";
?>

<?php 
// Temporary hack to simulate logged in user
$user_id = 1;
if (isset($_POST['submit-new-mc-question'])) {
    // The New Multiple Choice Form was submitted
    // Validate New User Form inputs
    $fields_required = array("question_text", "answer1", "answer2", "answer3", "answer4", "weight");
    foreach ($fields_required as $field) {
        $value = trim($_POST[$field]);
        if (!has_presence($value)) {
            $error_messages[$field] = ucfirst($field) . " is required.";
        }
    }
    // If there were errors, redirect back to the form.
    if (!empty($error_messages)) {
        $_SESSION["errors"] = $error_messages;
        $form_values = array("question_text" => $_POST['question_text'], "answer1" => $_POST['answer1'], "answer2" => $_POST['answer2'], "answer3" => $_POST['answer3'], "answer4" => $_POST['answer4'], "weight" => $_POST['weight']);
        $_SESSION["form_history"] = $form_values;
        redirect_to("new-question.php");
    }
    // If inputs were valid begin insertion.
    $_POST = array_map('mysql_real_escape_string', $_POST);
    $question_text = $_POST['question_text'];
    $answer1 = $_POST['answer1'];
    $answer2 = $_POST['answer2'];
Beispiel #13
0
 foreach ($fields_required as $field) {
     $value = trim($_POST[$field]);
     if (!has_presence($value)) {
         $error_messages[$field] = ucfirst($field) . " is required.";
     }
 }
 // If there are no errors, proceed with the update.
 if (empty($error_messages)) {
     $_POST = array_map('addslashes', $_POST);
     $_POST = array_map('htmlentities', $_POST);
     $quiz_id = $id;
     $quiz_name = $_POST['quiz_name'];
     $category = $_POST['category'];
     $deadline = $_POST['deadline'];
     $attempts = $_POST['attempts'];
     if (!has_presence($deadline)) {
         $query = "UPDATE quiz SET ";
         $query .= "quiz_name = '{$quiz_name}', ";
         $query .= "category = '{$category}', ";
         $query .= "deadline = NULL, ";
         $query .= "attempts = '{$attempts}' ";
         $query .= "WHERE quiz_id = {$quiz_id} ";
         $query .= "LIMIT 1";
     } else {
         $query = "UPDATE quiz SET ";
         $query .= "quiz_name = '{$quiz_name}', ";
         $query .= "category = '{$category}', ";
         $query .= "deadline = '{$deadline}', ";
         $query .= "attempts = '{$attempts}' ";
         $query .= "WHERE quiz_id = {$quiz_id} ";
         $query .= "LIMIT 1";
Beispiel #14
0
    if (!$result2) {
        die("database failed at layou1_edit form starting." . mysqli_error($connection));
    }
    $row2 = mysqli_fetch_assoc($result2);
}
if (!check_auth("3")) {
    $_SESSION["message"] = "Not Authorised To Approve Or Cancel Jumper";
    $_SESSION["message_color"] = "red";
    if (isset($_GET["jumperid"])) {
        redirect_to("layout2.php?jumperid={$_GET["jumperid"]}");
    } else {
        redirect_to("search.php");
    }
}
if (isset($_POST["app_jumper"])) {
    if (!has_presence($_POST["valid_upto"])) {
        //mandatory fields are not present
        $_SESSION["error_messages"][] = "All Field Marked * Are Mandatory.";
        redirect_to("layout2_edit.php?jumperid={$_GET["jumperid"]}");
    }
    if (!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}\$/", $_POST["valid_upto"])) {
        //mandatory fields are not present
        $_SESSION["error_messages"][] = "PLease Enter Valid Date";
        redirect_to("layout2_edit.php?jumperid={$_GET["jumperid"]}");
    }
    if (!($row2["vcStatus"] == "NEW")) {
        $_SESSION["message"] = "Approval can be given only once, to a New Jumper.";
        $_SESSION["message_color"] = "red";
        redirect_to("layout2.php?jumperid={$_GET["jumperid"]}");
    }
    //update the database
Beispiel #15
0
<!DOCTYPE html>
<html>
<head>
	<title>php</title>
</head>
<body>
	<?php 
require 'lynda_9.php';
$errors = array();
$username = trim("");
if (!has_presence($username)) {
    $errors['username'] = "******";
}
// print_r($errors);
echo form_errors($errors);
?>
	<body>
</html>
     } else {
         $email = htmlspecialchars($_POST['email']);
         $errors[] = "Please enter a valid email address";
     }
 } else {
     $email = "";
     $errors[] = "Please enter an email address";
 }
 // if there's a subject, clean it up
 if (has_presence($_POST['subject'])) {
     $subject = htmlspecialchars($_POST['subject']);
 } else {
     $subject = "";
 }
 // check for presence of a message
 if (has_presence($_POST['message'])) {
     // if it's at least 3 characters long
     if (has_min_length($_POST['message'], 3)) {
         $message = wordwrap(htmlspecialchars($_POST['message']), 70);
     } else {
         $message = htmlspecialchars($_POST['message']);
         $errors[] = "Please write more than 2 words";
     }
 } else {
     $message = "";
     $errors[] = "Please write a comment before trying to send the form.";
 }
 // if no errors, then assemble the email
 if (empty($errors)) {
     $to = 'David Gaskin <*****@*****.**>';
     // this may cause a bug on Windows systems
Beispiel #17
0
function validate_presences_non_post($required_fields, $record, $warning_me = false)
{
    // not coming from post but by query db returning record set eg program 1 record as arrey
    global $errors;
    global $warnings;
    $msg_presence = array();
    foreach ($required_fields as $field) {
        $value = trim($record[$field]);
        if (!has_presence($value)) {
            if ($warning_me) {
                $warnings[$field] = fieldname_as_text($field) . " n'est pas rempli";
                $msg_presence[$field] = $warnings[$field];
                //    $msg_presence[$field]=get_warning_error($warnings[$field],$warning_me);
                //  var_dump($warnings[$field]);
            } else {
                $errors[$field] = fieldname_as_text($field) . " n'est pas rempli ";
                $msg_presence[$field] = $errors[$field];
                //   $msg_presence[$field]=get_warning_error($errors[$field],$warning_me);;
            }
            //   var_dump(debug_backtrace());
        }
    }
    return $msg_presence;
}
Beispiel #18
0
    }
    if (!has_presence($address)) {
        array_push($errors, "Address can't be blank");
    } else {
        if (!preg_match('/^[a-zA-Z0-9\\s,\'-]+$/', $address)) {
            array_push($errors, "Invalid entry in address");
        }
    }
    if (!has_presence($gender)) {
        array_push($errors, "Please select a gender");
    } else {
        if ($gender != 'male' && $gender != 'female') {
            array_push($errors, "Please select a Valid gender");
        }
    }
    if (!has_presence($education)) {
        array_push($errors, "Please select a education type");
    }
    if (!empty($errors)) {
        /*If there are any errors print them else display the data*/
        echo "<p class='failure'>There were some errors while processing form</p>";
        echo "<ul class='failure'>";
        foreach ($errors as $error_value) {
            echo "<li>" . $error_value . "</li>";
        }
    } else {
        /*Display the form input*/
        ?>
			<p class='success'>Form Submission successfull</p>
			<table>
				<tr>
Beispiel #19
0
}
check_session_timeout();
if (!check_auth("2")) {
    $_SESSION["message"] = "Not Authorised To Edit Or Create Jumper";
    $_SESSION["message_color"] = "red";
    if (isset($_GET["jumperid"])) {
        redirect_to("layout1.php?jumperid={$_GET["jumperid"]}");
    } else {
        redirect_to("search.php");
    }
}
require_once "../includes/validation_functions.php";
if (isset($_POST["submit"])) {
    $_SESSION["error_messages"] = array();
    $flag = 0;
    if (!has_presence($_POST["loc_mod"]) || !has_presence($_POST["dr_no"]) || !has_presence($_POST["tag_unit"]) || !has_presence($_POST["tag_subsys"]) || !has_presence($_POST["proposed_till"]) || !has_presence($_POST["loc_mod"]) || !has_presence($_POST["reason_temp_chng"]) || !has_presence($_POST["jumper_desc"])) {
        //mandatory fields are not present
        $_SESSION["error_messages"][] = "All Field Marked * Are Mandatory.";
        $flag = 1;
    }
    if (!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}\$/", $_POST["proposed_till"])) {
        //Proposed date not of order yyyy-mm-dd
        $_SESSION["error_messages"][] = "Invalid Proposal Date.";
        $flag = 1;
    }
    if (!preg_match("/^[0-9]{1}-[0-9]{2}-[0-9]{2}-[0-9a-zA-Z]{2}-[0-9]{3}\$/", $_POST["dr_no"])) {
        //DR NO. not like 1-15-09-MM-002
        $_SESSION["error_messages"][] = "Invalid DR-No.";
        $flag = 1;
    } else {
        if (check_drno($_POST["dr_no"]) === 0) {