You are here

function profile2_regpath_validate_settings in Profile2 Registration Path 7

Same name and namespace in other branches
  1. 7.2 profile2_regpath.admin.inc \profile2_regpath_validate_settings()

Validate profile settings form values.

1 string reference to 'profile2_regpath_validate_settings'
_profile2_regpath_form_profile2_type_form_alter in ./profile2_regpath.admin.inc
Implements hook_form_FORM_ID_alter().

File

./profile2_regpath.admin.inc, line 167
Modifications to administrative forms.

Code

function profile2_regpath_validate_settings($form, &$form_state) {
  if ($form_state['values']['status'] == 1) {

    // Validate URL tail via regex. This also tests that path is not null.
    if (profile2_regpath_url_validator(trim($form_state['values']['path'])) == FALSE) {
      form_set_error('path', 'Error, you did not enter a valid URL.');
    }

    // Ensure that URL does not contain a '/'.
    // @todo move this to profile2_regpath_url_validator.
    if (strpos($form_state['values']['path'], '/')) {
      form_set_error('path', 'Error, you cannot use a "/" in your unique path. You may specify only a single segment of the URL.');
    }

    // Check to see if another module is using the selected path.
    // We must make exceptions for '/user' and other p2rp registered paths.
    if ($form_state['values']['path'] != 'user' && ($existing_item = menu_get_item($form_state['values']['path']))) {
      if ($existing_item['page_callback'] != '_profile2_regpath_user_login') {
        form_set_error('path', 'Error, that base path is already being used by another module.');
      }
    }

    // Check to see if selected path is being used by an alias.
    if ($existing_alias = drupal_lookup_path('source', $form_state['values']['path'])) {
      form_set_error('path', t('Error, that base path is already being used as an alias. Please select a different base path or remove the alias.'));
    }
  }
}