=== added file 'form_update.txt' --- /dev/null +++ form_update.txt @@ -0,0 +1,70 @@ +If you had a page which only contained a form: + + + +then just change it to: + + + +If you used another form_id or a callback (which is now called function_prefix): + + + +that becomes: + + + +Finally, if you had a page which contained a form and other things, then you need to move the form to a separate function: + + + +then you will need: + + + +Finally, system_settings_form now just needs an array, remove the +form_id. === modified file 'includes/form.inc' --- includes/form.inc +++ includes/form.inc @@ -20,20 +20,41 @@ * will attempt to validate it, using drupal_validate_form(), * and then submit the form using drupal_submit_form(). * - * @param $form_id - * A unique string identifying the form. Allows each form to be - * themed. Pass NULL to suppress the form_id parameter (produces - * a shorter URL with method=get) - * @param $form - * An associative array containing the structure of the form. - * @param $callback - * An optional callback that will be used in addition to the form_id. - * + * @param $form_handler + * A unique string identifying the form in the array returned from + * hook_forms. + * @param ... + * Any number of arguments passed to the form handler. */ -function drupal_get_form($form_id, &$form, $callback = NULL) { +function drupal_get_form($form_handler) { + static $forms; + + $args = func_get_args(); + $form_handler = array_shift($args); + if (!function_exists($form_handler)) { + if (!isset($forms)) { + $forms = module_invoke_all('forms'); + } + $form_definition = $forms[$form_handler]; + if (isset($form_definition['callback arguments'])) { + $args = array_merge($form_definition['callback arguments'], $args); + } + if (isset($form_definition['callback'])) { + $callback = $form_definition['callback']; + } + } + $form = call_user_func_array(isset($callback) ? $callback : $form_handler, $args); + return drupal_process_form($form_handler, $form); +} + +function drupal_process_form($form_handler, $form) { global $form_values, $form_submitted, $user, $form_button_counter; static $saved_globals = array(); + $form_id = isset($form['#form_id']) ? $form['#form_id'] : $form_handler; + if (isset($form['#function_prefix'])) { + $function_prefix = $form['#function_prefix']; + } // Save globals in case of indirect recursive call array_push($saved_globals, array($form_values, $form_submitted, $form_button_counter)); @@ -41,20 +62,20 @@ function drupal_get_form($form_id, &$for $form_submitted = FALSE; $form_button_counter = array(0, 0); - $form = drupal_build_form($form_id, $form, $callback); + $form = drupal_build_form($form_id, $form, $function_prefix); - if (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $callback))) { - drupal_validate_form($form_id, $form, $callback); + if (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $function_prefix))) { + drupal_validate_form($form_id, $form); // IE does not send a button value when there is only one submit button (and no non-submit buttons) // and you submit by pressing enter. // In that case we accept a submission without button values. if (($form_submitted || (!$form_button_counter[0] && $form_button_counter[1])) && !form_get_errors()) { - $redirect = drupal_submit_form($form_id, $form, $callback); + $redirect = drupal_submit_form($form_id, $form); drupal_redirect_form($form, $redirect); } } - $output = drupal_render_form($form_id, $form, $callback); + $output = drupal_render_form($form_id, $form, $function_prefix); list($form_values, $form_submitted, $form_button_counter) = array_pop($saved_globals); return $output; } @@ -69,11 +90,11 @@ function drupal_get_form($form_id, &$for * theming, and hook_form_alter functions. * @param $form * An associative array containing the structure of the form. - * @param $callback - * An optional callback that will be used in addition to the form_id. + * @param $function_prefix + * An optional function prefix that will be used in place of $form_id. * */ -function drupal_build_form($form_id, &$form, $callback = NULL) { +function drupal_build_form($form_id, &$form, $function_prefix = NULL) { $form['#type'] = 'form'; if (isset($form['#token'])) { // If the page cache is on and an anonymous user issues a GET request, @@ -105,8 +126,8 @@ function drupal_build_form($form_id, &$f if (function_exists($form_id .'_validate')) { $form['#validate'] = array($form_id .'_validate' => array()); } - elseif (function_exists($callback .'_validate')) { - $form['#validate'] = array($callback .'_validate' => array()); + elseif (function_exists($function_prefix .'_validate')) { + $form['#validate'] = array($function_prefix .'_validate' => array()); } } @@ -116,8 +137,8 @@ function drupal_build_form($form_id, &$f // $form_values because it will change later $form['#submit'] = array($form_id .'_submit' => array()); } - elseif (function_exists($callback .'_submit')) { - $form['#submit'] = array($callback .'_submit' => array()); + elseif (function_exists($function_prefix .'_submit')) { + $form['#submit'] = array($function_prefix .'_submit' => array()); } } @@ -141,11 +162,9 @@ function drupal_build_form($form_id, &$f * theming, and hook_form_alter functions. * @param $form * An associative array containing the structure of the form. - * @param $callback - * An optional callback that will be used in addition to the form_id. * */ -function drupal_validate_form($form_id, $form, $callback = NULL) { +function drupal_validate_form($form_id, $form) { global $form_values; static $validated_forms = array(); @@ -175,14 +194,12 @@ function drupal_validate_form($form_id, * theming, and hook_form_alter functions. * @param $form * An associative array containing the structure of the form. - * @param $callback - * An optional callback that will be used in addition to the form_id. * @return * A string containing the path of the page to display when processing * is complete. * */ -function drupal_submit_form($form_id, $form, $callback = NULL) { +function drupal_submit_form($form_id, $form) { global $form_values; $default_args = array($form_id, &$form_values); @@ -209,21 +226,21 @@ function drupal_submit_form($form_id, $f * theming, and hook_form_alter functions. * @param $form * An associative array containing the structure of the form. - * @param $callback - * An optional callback that will be used in addition to the form_id. + * @param $function_prefix + * An optional function prefix that will be used in addition to the form_id. * @return * A string containing the path of the page to display when processing * is complete. * */ -function drupal_render_form($form_id, &$form, $callback = NULL) { +function drupal_render_form($form_id, &$form, $function_prefix = NULL) { // Don't override #theme if someone already set it. if (!isset($form['#theme'])) { if (theme_get_function($form_id)) { $form['#theme'] = $form_id; } - elseif (theme_get_function($callback)) { - $form['#theme'] = $callback; + elseif (theme_get_function($function_prefix)) { + $form['#theme'] = $function_prefix; } } === modified file 'includes/menu.inc' --- includes/menu.inc +++ includes/menu.inc @@ -415,7 +415,12 @@ function menu_execute_active_handler() { $arguments = array_merge($arguments, explode('/', $arg)); } - return call_user_func_array($menu['callbacks'][$path]['callback'], $arguments); + $callback = $menu['callbacks'][$path]['callback']; + $return = call_user_func_array($callback, $arguments); + if (is_array($return)) { + return drupal_process_form($callback, $return); + } + return $return; } /** === modified file 'modules/aggregator/aggregator.module' --- modules/aggregator/aggregator.module +++ modules/aggregator/aggregator.module @@ -332,7 +332,7 @@ function aggregator_block($op, $delta = $form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']); } - return drupal_get_form('aggregator_form_category', $form); + return $form; } /** @@ -463,7 +463,7 @@ function aggregator_form_feed($edit = ar $form['fid'] = array('#type' => 'hidden', '#value' => $edit['fid']); } - return drupal_get_form('aggregator_form_feed', $form); + return $form; } /** @@ -1045,28 +1045,15 @@ function aggregator_page_category() { return _aggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = '. $category->cid .' ORDER BY timestamp DESC, iid DESC', arg(3)); } -/** - * Prints an aggregator page listing a number of feed items. Various - * menu callbacks use this function to print their feeds. - */ -function _aggregator_page_list($sql, $op, $header = '') { - $categorize = (user_access('administer news feeds') && ($op == 'categorize')); - - $output = '
'. t('There are no orphan pages.') .'
'; + $form['error'] = array('#value' => ''. t('There are no orphan pages.') .'
'); } + return $form; } function book_admin_edit_submit($form_id, $form_values) { === modified file 'modules/comment/comment.module' --- modules/comment/comment.module +++ modules/comment/comment.module @@ -891,7 +891,7 @@ function comment_render($node, $cid = 0) // Start a form, for use with comment control. $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args); if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { - $output .= comment_controls($mode, $order, $comments_per_page); + $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page); } while ($comment = db_fetch_object($result)) { @@ -916,7 +916,7 @@ function comment_render($node, $cid = 0) $output .= theme('pager', NULL, $comments_per_page, 0); if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { - $output .= comment_controls($mode, $order, $comments_per_page); + $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page); } } @@ -1043,7 +1043,7 @@ function comment_admin_overview($type = } $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments); $form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); - return drupal_get_form('comment_admin_overview', $form); + return $form; } /** @@ -1274,7 +1274,7 @@ function comment_validate($edit) { ** This is rendered by theme_comment_form. */ -function comment_form($edit, $title = NULL) { +function _comment_form($edit, $title = NULL) { global $user; $op = isset($_POST['op']) ? $_POST['op'] : ''; @@ -1421,8 +1421,12 @@ function comment_form($edit, $title = NU // Graft in extra form additions $form = array_merge($form, comment_invoke_comment($form, 'form')); + $form['#form_id'] = 'comment_form'; + return $form; +} - return theme('box', $title, drupal_get_form('comment_form', $form)); +function _comment_form($edit, $title = NULL) { + return theme('box', $title, drupal_get_form('_comment_form', $edit, $title)); } function comment_form_add_preview($form, $edit) { @@ -1575,7 +1579,7 @@ function comment_controls($mode = COMMEN '#weight' => 20, ); - return drupal_get_form('comment_controls', $form); + return $form; } function theme_comment_controls($form) { === modified file 'modules/contact/contact.module' --- modules/contact/contact.module +++ modules/contact/contact.module @@ -199,7 +199,7 @@ function contact_admin_edit($cid = NULL) '#value' => t('Submit'), ); - return drupal_get_form('contact_admin_edit', $form); + return $form; } /** @@ -297,14 +297,7 @@ function contact_admin_settings() { '#default_value' => variable_get('contact_default_status', 1), '#description' => t('Default status of the personal contact form for new users.'), ); - $form['submit'] = array('#type' => 'submit', - '#value' => t('Save configuration'), - ); - $form['reset'] = array('#type' => 'submit', - '#value' => t('Reset to defaults'), - ); - - return drupal_get_form('contact_admin_settings', $form, 'system_settings_form'); + return system_settings_form($form); } /** @@ -322,33 +315,7 @@ function contact_mail_user() { } else { drupal_set_title($account->name); - - $form['#token'] = $user->name . $user->mail; - $form['from'] = array('#type' => 'item', - '#title' => t('From'), - '#value' => $user->name .' <'. $user->mail .'>', - ); - $form['to'] = array('#type' => 'item', - '#title' => t('To'), - '#value' => $account->name, - ); - $form['subject'] = array('#type' => 'textfield', - '#title' => t('Subject'), - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['message'] = array('#type' => 'textarea', - '#title' => t('Message'), - '#rows' => 15, - '#required' => TRUE, - ); - $form['copy'] = array('#type' => 'checkbox', - '#title' => t('Send me a copy.'), - ); - $form['submit'] = array('#type' => 'submit', - '#value' => t('Send e-mail'), - ); - $output = drupal_get_form('contact_mail_user', $form); + $output = drupal_get_form('contact_mail_user_form'); } return $output; @@ -358,6 +325,36 @@ function contact_mail_user() { } } +function contact_mail_user_form() { + $form['#token'] = $user->name . $user->mail; + $form['from'] = array('#type' => 'item', + '#title' => t('From'), + '#value' => $user->name .' <'. $user->mail .'>', + ); + $form['to'] = array('#type' => 'item', + '#title' => t('To'), + '#value' => $account->name, + ); + $form['subject'] = array('#type' => 'textfield', + '#title' => t('Subject'), + '#maxlength' => 50, + '#required' => TRUE, + ); + $form['message'] = array('#type' => 'textarea', + '#title' => t('Message'), + '#rows' => 15, + '#required' => TRUE, + ); + $form['copy'] = array('#type' => 'checkbox', + '#title' => t('Send me a copy.'), + ); + $form['submit'] = array('#type' => 'submit', + '#value' => t('Send e-mail'), + ); + $form['#form_id'] = 'contact_mail_user'; + return $form; +} + /** * Process the personal contact page form submission. */ @@ -416,77 +413,79 @@ function contact_mail_page() { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); } else { - if ($user->uid) { - $edit['name'] = $user->name; - $edit['mail'] = $user->mail; - } + $output = drupal_get_form('contact_mail_page_form'); + } - $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category'); - while ($category = db_fetch_object($result)) { - $categories[$category->cid] = $category->category; - if ($category->selected) { - $default_category = $category->cid; - } - } + return $output; +} - if (count($categories) > 0) { - $form['#token'] = $user->name . $user->mail; - $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave us a message using the contact form below.')))); - $form['name'] = array('#type' => 'textfield', - '#title' => t('Your name'), - '#maxlength' => 255, - '#default_value' => $edit['name'], - '#required' => TRUE, - ); - $form['mail'] = array('#type' => 'textfield', - '#title' => t('Your e-mail address'), - '#maxlength' => 255, - '#default_value' => $edit['mail'], - '#required' => TRUE, - ); - $form['subject'] = array('#type' => 'textfield', - '#title' => t('Subject'), - '#maxlength' => 255, - '#required' => TRUE, - ); - if (count($categories) > 1) { - // If there is more than one category available and no default category has been selected, - // prepend a default placeholder value. - if (!isset($default_category)) { - $categories = array(t('--')) + $categories; - } - $form['cid'] = array('#type' => 'select', - '#title' => t('Category'), - '#default_value' => $default_category, - '#options' => $categories, - '#required' => TRUE, - ); - } - else { - // If there is only one category, store its cid. - $category_keys = array_keys($categories); - $form['cid'] = array('#type' => 'value', - '#value' => array_shift($category_keys), - ); +function contact_mail_page_form() { + global $user; + + $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category'); + while ($category = db_fetch_object($result)) { + $categories[$category->cid] = $category->category; + if ($category->selected) { + $default_category = $category->cid; + } + } + + if (count($categories) > 0) { + $form['#token'] = $user->name . $user->mail; + $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave us a message using the contact form below.')))); + $form['name'] = array('#type' => 'textfield', + '#title' => t('Your name'), + '#maxlength' => 255, + '#default_value' => $user->uid ? $user->name : '', + '#required' => TRUE, + ); + $form['mail'] = array('#type' => 'textfield', + '#title' => t('Your e-mail address'), + '#maxlength' => 255, + '#default_value' => $user->uid ? $user->mail : '', + '#required' => TRUE, + ); + $form['subject'] = array('#type' => 'textfield', + '#title' => t('Subject'), + '#maxlength' => 255, + '#required' => TRUE, + ); + if (count($categories) > 1) { + // If there is more than one category available and no default category has been selected, + // prepend a default placeholder value. + if (!isset($default_category)) { + $categories = array(t('--')) + $categories; } - $form['message'] = array('#type' => 'textarea', - '#title' => t('Message'), + $form['cid'] = array('#type' => 'select', + '#title' => t('Category'), + '#default_value' => $default_category, + '#options' => $categories, '#required' => TRUE, ); - $form['copy'] = array('#type' => 'checkbox', - '#title' => t('Send me a copy.'), - ); - $form['submit'] = array('#type' => 'submit', - '#value' => t('Send e-mail'), - ); - $output = drupal_get_form('contact_mail_page', $form); } else { - $output = t('The contact form has not been configured.'); + // If there is only one category, store its cid. + $category_keys = array_keys($categories); + $form['cid'] = array('#type' => 'value', + '#value' => array_shift($category_keys), + ); } + $form['message'] = array('#type' => 'textarea', + '#title' => t('Message'), + '#required' => TRUE, + ); + $form['copy'] = array('#type' => 'checkbox', + '#title' => t('Send me a copy.'), + ); + $form['submit'] = array('#type' => 'submit', + '#value' => t('Send e-mail'), + ); } - - return $output; + else { + $form['#error'] = array('#value' => t('The contact form has not been configured.')); + } + $form['#form_id'] = 'contact_mail_page'; + return $form; } /** === modified file 'modules/filter/filter.module' --- modules/filter/filter.module +++ modules/filter/filter.module @@ -316,7 +316,7 @@ function filter_admin_overview() { } $form['default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('filter_default_format', 1)); $form['submit'] = array('#type' => 'submit', '#value' => t('Set default format')); - return drupal_get_form('filter_admin_overview', $form); + return $form; } function filter_admin_overview_submit($form_id, $form_values) { @@ -440,8 +440,6 @@ function filter_admin_format_form($forma '#description' => module_invoke($filter->module, 'filter', 'description', $filter->delta), ); } - $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - if (isset($format)) { $form['format'] = array('#type' => 'hidden', '#value' => $format->format); @@ -454,11 +452,11 @@ function filter_admin_format_form($forma } $group = t('These are the guidelines that users will see for posting in this input format. They are automatically generated from the filter settings.
'); $group .= $tiplist; - $output = ''. t("No image toolkits found. Drupal will use PHP's built-in GD library for image handling.") .'
'; + $form['error'] = array('#value' => ''. t("No image toolkits found. Drupal will use PHP's built-in GD library for image handling.") .'
'); + return $form; } } @@ -648,7 +649,7 @@ function system_rss_feeds_settings() { '#description' => t('Global setting for the length of XML feed items that are output by default.') ); - return system_settings_form('system_rss_feeds_settings', $form); + return system_settings_form($form); } function system_date_time_settings() { @@ -726,7 +727,7 @@ function system_date_time_settings() { '#description' => t('The first day of the week for calendar views.') ); - return system_settings_form('system_date_time_settings', $form); + return system_settings_form($form); } function system_site_status_settings() { @@ -746,11 +747,12 @@ function system_site_status_settings() { '#description' => t('Message to show visitors when the site is in off-line mode.') ); - return system_settings_form('system_site_status_settings', $form); + return system_settings_form($form); } function system_unicode_settings() { - return system_settings_form('system_unicode_settings', unicode_settings()); + $form = unicode_settings(); + return system_settings_form($form); } function system_cron_status($cron = '') { @@ -1018,16 +1020,18 @@ function system_initialize_theme_blocks( } } -// Add the submit / reset buttons and run drupal_get_form() -function system_settings_form($form_id, $form) { +/** + * Add default buttons to a form and set its prefix + */ +function system_settings_form($form) { $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); if (!empty($_POST) && form_get_errors()) { drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); } - - return drupal_get_form($form_id, $form, 'system_settings_form'); + $form['#function_prefix'] = 'system_settings_form'; + return $form; } function system_theme_settings_submit($form_id, $values) { @@ -1111,7 +1115,7 @@ function system_themes() { $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); - return drupal_get_form('system_themes', $form); + return $form; } function theme_system_themes($form) { @@ -1210,7 +1214,7 @@ function system_modules() { $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - return drupal_get_form('system_modules', $form); + return $form; } function theme_system_modules($form) { @@ -1479,9 +1483,9 @@ function system_theme_settings($key = '' } } $form['#attributes'] = array('enctype' => 'multipart/form-data'); +// $form['#render_prefix'] = 'confirm_form'; - return system_settings_form('system_theme_settings', $form); - + return system_settings_form($form); } /** @@ -1527,7 +1531,7 @@ function confirm_form($form_id, $form, $ $form['actions'] = array('#prefix' => 'This login can be used only once.
')); $form['submit'] = array('#type' => 'submit', '#value' => t('Log in')); $form['#action'] = url("user/reset/$uid/$timestamp/$hashed_pass/login"); - return drupal_get_form('user_pass_reset', $form); + return $form; } } else { @@ -1110,6 +1117,7 @@ function user_pass_reset($uid, $timestam // Deny access, no more clues. // Everything will be in the watchdog's URL for the administrator to check. drupal_access_denied(); + exit; } } } @@ -1174,7 +1182,7 @@ function user_register() { } $form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30); - return drupal_get_form('user_register', $form); + return $form; } function user_register_validate($form_id, $form_values) { @@ -1404,7 +1412,7 @@ function user_edit($category = 'account' $form['#attributes']['enctype'] = 'multipart/form-data'; drupal_set_title($account->name); - return drupal_get_form('user_edit', $form); + return $form; } /** @@ -1511,31 +1519,43 @@ function _user_mail_text($messageid, $va } } -/** - * Menu callback: check an access rule - */ -function user_admin_access_check() { +function user_admin_check_user() { $form['user'] = array('#type' => 'fieldset', '#title' => t('Username')); $form['user']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a username to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => 64); $form['user']['type'] = array('#type' => 'hidden', '#value' => 'user'); $form['user']['submit'] = array('#type' => 'submit', '#value' => t('Check username')); - $output .= drupal_get_form('check_user', $form, 'user_admin_access_check'); - unset($form); // prevent endless loop? + $form['#function_prefix'] = 'user_admin_access_check'; + $form['#form_id'] = 'check_user'; + return $form; +} +function user_admin_check_mail() { $form['mail'] = array('#type' => 'fieldset', '#title' => t('E-mail')); $form['mail']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter an e-mail address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => 64); $form['mail']['type'] = array('#type' => 'hidden', '#value' => 'mail'); $form['mail']['submit'] = array('#type' => 'submit', '#value' => t('Check e-mail')); - $output .= drupal_get_form('check_mail', $form, 'user_admin_access_check'); - unset($form); // prevent endless loop? + $form['#function_prefix'] = 'user_admin_access_check'; + $form['#form_id'] = 'check_mail'; + return $form; +} +function user_admin_check_host() { $form['host'] = array('#type' => 'fieldset', '#title' => t('Hostname')); $form['host']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a hostname or IP address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => 64); $form['host']['type'] = array('#type' => 'hidden', '#value' => 'host'); $form['host']['submit'] = array('#type' => 'submit', '#value' => t('Check hostname')); - $output .= drupal_get_form('check_host', $form, 'user_admin_access_check'); - unset($form); // prevent endless loop? + $form['#function_prefix'] = 'user_admin_access_check'; + $form['#form_id'] = 'check_host'; + return $form; +} +/** + * Menu callback: check an access rule + */ +function user_admin_access_check() { + $output = drupal_get_form('user_admin_check_user'); + $output .= drupal_get_form('user_admin_check_mail'); + $output .= drupal_get_form('user_admin_check_host'); return $output; } @@ -1596,10 +1616,7 @@ function user_admin_access_add($mask = N $edit['type'] = $type; } - $form = _user_admin_access_form($edit); - $form['submit'] = array('#type' => 'submit', '#value' => t('Add rule')); - - return drupal_get_form('access_rule', $form); + return drupal_get_form('user_admin_access_form', $edit, 'access_rule', t('Add rule')); } /** @@ -1643,13 +1660,11 @@ function user_admin_access_edit($aid = 0 else { $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); } - $form = _user_admin_access_form($edit); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save rule')); - - return drupal_get_form('access_rule', $form); + return drupal_get_form('user_admin_access_form', $edit, 'access_edit', t('Save rule')); } -function _user_admin_access_form($edit) { +function user_admin_access_form($edit, $form_id, $submit) { + $form['#form_id'] = $form_id; $form['status'] = array( '#type' => 'radios', '#title' => t('Access type'), @@ -1672,6 +1687,8 @@ function _user_admin_access_form($edit) '#description' => '%: '. t('Matches any number of characters, even zero characters') .'.