function student_files_upload_any_student_files_form_validate

7.x student_files.module student_files_upload_any_student_files_form_validate($form, &$form_state)
6.x student_files.module student_files_upload_any_student_files_form_validate($form, &$form_state)

Validate function.


modules/student_files/student_files.module, line 176
This is the student_files module, which will facilitate uploading (securely) files to be associated with student accounts.


function student_files_upload_any_student_files_form_validate($form, &$form_state) {

  $values = $form_state ["values"];
  $db = get_global_database_handler();

  // Re-order the _FILES array to make it easier to work with
  $student_files = fp_re_array_files($_FILES ["student_files"]);
  $form_state ["student_files"] = $student_files;

  // Make sure if "manual" is selected, that the CWID entered actually exists.
  if ($values ["student_method"] == "manual") {
    $n = @trim($db->get_student_name($values ["manual_cwid"]));

    if (!$n) {
      // Student not found!  Or at least their name wasn't found.
      form_error("student_method", t("Sorry, the CWID you entered could not be found."));

  // if a filename method selected, make sure a CWID is detectable and valid.  Maybe save it to form_state for the _submit function.
  // If more than one file, check all the files...
  if ($values ["student_method"] == "filename") {
    $is_empty = TRUE;
    foreach ($form_state ["student_files"] as $c => $file) {

      if (trim($file ["name"] == "")) {
      $is_empty = FALSE;

      $temp = explode("_", $file ["name"]);
      $test_cwid = trim($temp [0]);
      $n = @trim($db->get_student_name($test_cwid));
      if (!$n) {
        // Student not found!  Or at least their name wasn't found.
        form_error("student_files", t("Sorry, the file named %file either does not begin with a CWID, or the CWID does not match
                                        a current student.  Please try again.", array("%file" => $file ["name"])));
      else {
        // This IS a valid student.  Save the CWID with the form_state to make our lives easier later.
        $form_state ["student_files"][$c]["cwid"] = $test_cwid;
        // Also save the filename where we have stripped off the CWID
        $form_state ["student_files"][$c]["name"] = str_replace($test_cwid . "_", "", $file ["name"]);


    if ($is_empty) {
      form_error("student_files", t("No files were selected.  Please try again."));

  } // if student_method = filename