You are here

function regcode_admin_import_validate in Registration codes 6

Handle the processing of a submitted import form

File

./regcode.admin.php, line 317
Functions and pages needed for the administration interface for the regcode module.

Code

function regcode_admin_import_validate($form, &$form_state) {
  variable_set('regcode_import_delimiter', $form_state['values']['regcode_import_delimiter']);
  variable_set('regcode_import_enclosure', $form_state['values']['regcode_import_enclosure']);
  variable_set('regcode_import_fieldorder', $form_state['values']['regcode_import_fieldorder']);

  // Validators for file
  $validators = array(
    'file_validate_extensions' => array(
      'csv',
      'txt',
    ),
  );

  // Save the file
  if ($file = file_save_upload('regcode_import_file', $validators, file_directory_path())) {
    $form_state['values']['fileobj'] = $file;
    drupal_set_message(t('File successfully saved'));
  }
  else {
    form_set_error('regcode_import_file', t('Unable to parse CSV file'));
    return FALSE;
  }
}