You are here

function user_import_edit_validate in User Import 6.4

Same name and namespace in other branches
  1. 8 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()

File

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

Code

function user_import_edit_validate($form, &$form_state) {
  $email = FALSE;
  $fields = array();
  $import_key = $form_state['values']['import_key'];
  $import_key_match = FALSE;
  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;
    }

    // Check Import Key has a corresponding Field Match.
    if ($values['field_match'] == $import_key) {
      $import_key_match = TRUE;
    }
  }
  if (!$email) {
    form_set_error('email', t('One column of the csv file must be set as the email address.'));
  }
  if ($import_key != 'user-email' && !$import_key_match) {
    form_set_error('import_key', t('There must be a Field Match for the Import Key field.'));
  }
  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.'));
    }
  }
  return;
}