You are here

function autoupload_admin_form_validate in AutoUpload 7

Validation handler for autoupload settings form.

File

./autoupload.admin.inc, line 249
Contains the administrative functions of the autoupload module.

Code

function autoupload_admin_form_validate($form, &$form_state) {
  $values = $form_state['values'];
  $names = array();
  foreach ($values['custom_type'] as $key => $value) {
    if ($value['name'] == '' && $value['context'] == '' && $value['file_input'] == '' && $value['file_event'] == '' && $value['submit_input'] == '' && $value['submit_event'] == '' && $value['error'] == '') {
      continue;
    }

    // Make sure machine names are unique.
    if (in_array($value['name'], $names)) {
      form_set_error('custom_type][' . $key . '][name', t('Name %name is already used. Please enter a unique name for each configuration.', array(
        '%name' => $value['name'],
      )));
    }
    else {
      $names[] = $value['name'];
    }

    // Make sure names are only letters, numbers, and underscores.
    if (preg_match('/[^a-zA-Z0-9_]/', $value['name']) !== 0) {
      form_set_error('custom_type][' . $key . '][name', t('Name %name is invalid. Only letters, numbers, and underscores allowed.', array(
        '%name' => $value['name'],
      )));
    }
    if ($value['name'] == '') {
      form_set_error('custom_type][' . $key . '][name', t('Name cannot be empty.'));
    }
    if ($value['context'] == '') {
      form_set_error('custom_type][' . $key . '][context', t('Context cannot be empty.'));
    }
    if ($value['file_input'] == '') {
      form_set_error('custom_type][' . $key . '][file_input', t('File input selector cannot be empty.'));
    }
    if ($value['file_event'] == '') {
      form_set_error('custom_type][' . $key . '][file_event', t('File event cannot be empty.'));
    }
    if ($value['submit_input'] == '') {
      form_set_error('custom_type][' . $key . '][submit_input', t('Submit input selector cannot be empty.'));
    }
    if ($value['submit_event'] == '') {
      form_set_error('custom_type][' . $key . '][submit_event', t('Submit event cannot be empty.'));
    }
  }
}