function autoassignrole_admin_form_validate in Auto Assign Role 6
Same name and namespace in other branches
- 6.2 autoassignrole-admin.inc \autoassignrole_admin_form_validate()
File
- ./autoassignrole-admin.inc, line 256
- The autoassignrole-admin.inc file
Code
function autoassignrole_admin_form_validate($form_id, &$form_state) {
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
$registration = array();
foreach ($roles as $rid => $role) {
if ($form_state['values']["path_active_{$rid}"]) {
$format = $form_state['values']["path_format_{$rid}"];
$path = $form_state['values']["path_{$rid}"];
$title = $form_state['values']["path_title_{$rid}"];
$description = $form_state['values']["path_description_{$rid}"];
$display = $form_state['values']["path_display_{$rid}"];
if ($form_state['values']["path_registration_{$rid}"]) {
$registration[] = $rid;
if ($display == 1) {
form_set_error("path_display_{$rid}", t('If a path serves as the default user registration page it can not have a Display Method of Tabs on registration page'));
}
}
if ($display == '') {
form_set_error("path_display_{$rid}", t('Please select a valid display method for enabled URL role assignments'));
}
if ($path) {
if (ereg("[^A-Za-z0-9/_-]+", $path) || strpos(trim($path), '/') === 0) {
form_set_error("path_{$rid}", '\'' . check_plain($path) . '\' ' . t('is not a valid path'));
}
else {
$menu_link = db_fetch_object(db_query("SELECT count(mlid) AS count FROM {menu_links} where link_path like '%s'", $path));
if (drupal_lookup_path('source', $path) || $menu_link->count > 0) {
$menu_item = menu_get_item($path);
if (!isset($menu_item['page_callback']) && $menu_item['page_callback'] != 'autoassign_role_path') {
form_set_error("path_{$rid}", '\'' . check_plain($path) . '\' ' . t('is already in use as a path'));
}
}
if ($display == 1 && (strpos(trim($path), 'register') === 0 || strpos(trim($path), 'password') === 0)) {
form_set_error("path_{$rid}", '\'' . check_plain($path) . '\' ' . t('can only be used as a path if the Display Method is not Tabs on registration page.'));
}
}
}
else {
form_set_error("path_{$rid}", t('Please enter a valid path for enabled URL role assignments'));
}
if ($display == '0' || $display == '1') {
$title = ereg_replace('[:space:]', '', $title);
if (!strlen($title)) {
form_set_error("path_title_{$rid}", t('Please enter a valid title for enabled URL role assignments'));
}
}
}
}
if (count($registration) > 1) {
form_set_error(NULL, t('Only one path can can serve as the default user register page'));
}
if (count($registration) > 0 && !empty($form_state['values']['node_user_register'])) {
form_set_error('node_user_register', t('You can not replace the user register page with a node if a path has been designated as the user register page.'));
}
if ($form_state['values']['user_active'] == 1) {
if ($form_state['values']['user_multiple'] == 1 && $form_state['values']['user_selection'] == 0) {
form_set_error('user_selection', t('If a user can select multiple roles they can not use Radio Buttons as the selection method.'));
}
if (strlen(trim($form_state['values']['user_title'])) == 0) {
form_set_error('user_title', t('Enter the title of the form fields the user will be presented with.'));
}
}
}