You are here

function user_import_edit_validate in User Import 8

Same name and namespace in other branches
  1. 6.4 user_import.admin.inc \user_import_edit_validate()
  2. 6.2 user_import.admin.inc \user_import_edit_validate()
  3. 7.3 user_import.admin.inc \user_import_edit_validate()
  4. 7 user_import.admin.inc \user_import_edit_validate()
  5. 7.2 user_import.admin.inc \user_import_edit_validate()
1 string reference to 'user_import_edit_validate'
_user_import_edit_template_fields in supported/user_import.inc

File

./user_import.admin.inc, line 546
Provide administration configuration pages to import users.

Code

function user_import_edit_validate($form, &$form_state) {
  $email = FALSE;
  $fields = array();
  foreach ($form_state['values']['field_match'] as $row => $values) {

    // check each field is unique
    if ($values['field_match'] != '0' && $values['field_match'] != '-------------' && in_array($values['field_match'], $fields)) {
      form_set_error('field_match', t('Database fields can only be matched to one column of the csv file.'));
    }
    $fields[$values['field_match']] = $values['field_match'];

    // check email address has been selected
    if ($values['field_match'] == 'user-email') {
      $email = TRUE;
    }
  }
  if (!$email) {
    form_set_error('email', t('One column of the csv file must be set as the email address.'));
  }
  if ($form_state['values']['name']) {
    $form_state['values']['name'] = rtrim($form_state['values']['name']);
    if (drupal_strlen($form_state['values']['name']) < 1 || drupal_strlen($form_state['values']['name']) > 25) {
      form_set_error('name', t('Name of saved settings must be 25 characters or less.'));
    }
  }

  // Check auto uploads directory is not already in use by another template.
  if (!empty($form_state['values']['auto_import_directory'])) {
    $auto_import_directory = 'private://user_import/uploads/' . $form_state['values']['auto_import_directory'];
    if (file_prepare_directory($auto_import_directory, FILE_MODIFY_PERMISSIONS) || $form_state['values']['auto_import_directory'] == 'selectable') {
      form_set_error('auto_import_directory', t("Directory '%directory' already exists and can not be used.", array(
        '%directory' => $form_state['values']['auto_import_directory'],
      )));
    }
  }
  return;
}