function admin_add_degree_form_validate
Search API
7.x admin.degrees.inc | admin_add_degree_form_validate($form, $form_submit) |
6.x admin.degrees.inc | admin_add_degree_form_validate($form, $form_submit) |
5.x admin.degrees.inc | admin_add_degree_form_validate($form, $form_submit) |
Validate handler for add_degree_form
File
- modules/
admin/ admin.degrees.inc, line 580
Code
function admin_add_degree_form_validate($form, $form_submit) {
$values = $form_submit ["values"];
// Make sure neither major code nor track code contains any spaces.
$de_catalog_year = $values ["de_catalog_year"];
$major_code = trim(strtoupper($values ["major_code"]));
$track_code = trim(strtoupper($values ["track_code"]));
$school_id = intval($values ["school_id"]);
$new_major = $values ["new_major"];
$new_track = $values ["new_track"];
if ($major_code != "" && admin_string_contains_illegal_chars($major_code)) {
form_error("major_code", t("The major code may not contain spaces or symbols. Please enter a new one containing only letters, numbers, and -."));
}
if ($track_code != "" && admin_string_contains_illegal_chars($track_code)) {
form_error("track_code", t("The track code may not contain spaces or symbols. Please enter a new one containing only letters, numbers, and -."));
}
// Make sure the major + |_ + track_code doesn't exceed 20 characters.
if (strlen("$major_code|_$track_code") > 20) {
form_error("major_code", t("The major and track code combined may not exceed 18 characters. Please shorten one or the other."));
}
if ($new_track == "new" && $track_code == "") {
form_error("track_code", t("You selected to add a track, but did not specify a track code."));
}
$for_school = $school_name = "";
if (module_enabled("schools")) {
$for_school = " for school %school";
$school_name = schools_get_school_name_for_id($school_id);
}
// Check to see if it already exists...
$res = db_query("SELECT * FROM draft_degrees
WHERE catalog_year = ?
AND major_code = ?
AND school_id = ?", $de_catalog_year, $major_code, $school_id);
if (db_num_rows($res) > 0 && $new_major == "new") {
// Meaning, it already exists, yet we are trying to add it as a new
// major. This is an error!
form_error('major_code', t("The major code %major_code already exists for %year$for_school. You cannot add it as a new major.", array("%major_code" => $major_code, "%year" => $de_catalog_year, "%school" => $school_name)));
}
if (db_num_rows($res) == 0 && $new_major == "existing") {
// This is another error. We are trying to add a track to an existing
// major code, but none was found.
form_error('major_code', t("The major code %major_code could not be found in the system for %year$for_school. Perhaps you need to add it first?", array("%major_code" => $major_code, "%year" => $de_catalog_year, "%school" => $school_name)));
return;
}
}