function file_upload_combo_value_callback

2.x tripal_core.form_elements.inc file_upload_combo_value_callback($element, $input = FALSE, &$form_state)
3.x tripal_core.form_elements.inc file_upload_combo_value_callback($element, $input = FALSE, &$form_state)

Validate all content passed into the file upload combo form element.

Related topics

1 string reference to 'file_upload_combo_value_callback'
tripal_core_element_info in tripal_core/includes/tripal_core.form_elements.inc
Register form elements.

File

tripal_core/includes/tripal_core.form_elements.inc, line 104
Form elements used Various places in Tripal

Code

function file_upload_combo_value_callback($element, $input = FALSE, &$form_state) {
  $values = array();

  if ($input == FALSE) {
    if (!empty($element['#default_value'])) {
      return $element['#default_value'];
    }
    else {
      return;
    }
  }

  // get the items in the textbox
  $items = $input['items'];
  if ($items) {
    // split on new line or comma
    $vals = preg_split("/[\n,]+/", $items);
    // iterate through the values and trim surrounding space
    foreach ($vals as $i => $value) {
      $values[] = trim($value);
    }
  }

  // merge any items from the file upload
  $file = file_save_upload($element['#name'], array());
  if ($file) {
    $file_path = $file->uri;

    $input['file_path'] = $file_path;
    // we need to add our file path to the $_GET element as if it were
    // submitted along with the rest of the form
    $_GET[$element['#name']]['file_path'] = $file_path;

    $fh = fopen($file_path, 'r');
    while ($line = fgets($fh)) {
      $items = trim($line);

      // split on new line or comma
      $vals = preg_split("/[\n,]+/", $items);
      // iterate through the values and trim surrounding space
      foreach ($vals as $i => $value) {
        $values[] = trim($value);
      }
    }
    fclose($fh);
  }

  // add a new 'items_array' element that contains the array of
  // submitted items from both the textbox and the input file
  $input['items_array'] = $values;
  return $input;
}