diff --git a/includes/form.inc b/includes/form.inc index d0a8e5dbe082e878fd1d2770a8f457c67c701715..d8f364266489b8a509d19a3694c1334c5c0a6ed3 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -17,13 +17,13 @@ * $output = drupal_get_form('user_register'); * * Forms can also be built and submitted programmatically without any user input - * by populating $form['#post']['edit'] with values to be submitted. For example: + * by populating $form['#post'] with values to be submitted. For example: * * // register a new user * $form = drupal_retrieve_form('user_register'); - * $form['#post']['edit']['name'] = 'robo-user'; - * $form['#post']['edit']['mail'] = 'robouser@example.com'; - * $form['#post']['edit']['pass'] = 'password'; + * $form['#post']['name'] = 'robo-user'; + * $form['#post']['mail'] = 'robouser@example.com'; + * $form['#post']['pass'] = 'password'; * drupal_process_form('user_register', $form); * * Calling form_get_errors() will list any validation errors that prevented the @@ -92,18 +92,18 @@ function drupal_get_form($form_id) { // to the builder function, as values from one stage of a multistep // form can determine how subsequent steps are displayed. $args = func_get_args(); - $args[] = $_POST['edit']; + $args[] = $_POST; $form = call_user_func_array('drupal_retrieve_form', $args); unset($_SESSION['form'][$_POST['form_build_id']]); if (isset($form['#multistep']) && $form['#multistep']) { $_SESSION['form'][$form_build_id] = $args; $form['#build_id'] = $form_build_id; } - // If we're in this part of the code, $_POST['edit'] always contains + // If we're in this part of the code, $_POST always contains // values from the previously submitted form. Unset it to avoid // any accidental submission of doubled data, then process the form // to prep it for rendering. - unset($_POST['edit']); + unset($_POST); drupal_process_form($args[0], $form); } @@ -168,7 +168,7 @@ function drupal_process_form($form_id, &$form) { $form_button_counter = array(0, 0); drupal_prepare_form($form_id, $form); - if (($form['#programmed']) || (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $form['#base'])))) { + if (($form['#programmed']) || (!empty($_POST) && (($_POST['form_id'] == $form_id) || ($_POST['form_id'] == $form['#base'])))) { 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. @@ -550,10 +550,15 @@ function form_builder($form_id, $form) { if (isset($form['#input']) && $form['#input']) { if (!isset($form['#name'])) { - $form['#name'] = 'edit[' . implode('][', $form['#parents']) . ']'; + $name = array_shift($form['#parents']); + $form['#name'] = $name; + if (count($form['#parents'])) { + $form['#name'] .= '['. implode('][', $form['#parents']) .']'; + } + array_unshift($form['#parents'], $name); } if (!isset($form['#id'])) { - $form['#id'] = 'edit-' . implode('-', $form['#parents']); + $form['#id'] = 'edit-'. implode('-', $form['#parents']); } if (isset($form['#disabled']) && $form['#disabled']) { @@ -561,8 +566,8 @@ function form_builder($form_id, $form) { } if (!isset($form['#value']) && !array_key_exists('#value', $form)) { - if (($form['#programmed']) || ((!isset($form['#access']) || $form['#access']) && isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id))) { - $edit = $form['#post']['edit']; + if (($form['#programmed']) || ((!isset($form['#access']) || $form['#access']) && isset($form['#post']) && ($form['#post']['form_id'] == $form_id))) { + $edit = $form['#post']; foreach ($form['#parents'] as $parent) { $edit = isset($edit[$parent]) ? $edit[$parent] : NULL; } @@ -619,8 +624,13 @@ function form_builder($form_id, $form) { // Count submit and non-submit buttons $form_button_counter[$form['#executes_submit_callback']]++; // See if a submit button was pressed - if (isset($_POST[$form['#name']]) && $_POST[$form['#name']] == $form['#value']) { + if (isset($form['#post'][$form['#name']]) && $form['#post'][$form['#name']] == $form['#value']) { $form_submitted = $form_submitted || $form['#executes_submit_callback']; + + // In most cases, we want to use form_set_value() to manipulate the global variables. + // In this special case, we want to make sure that the value of this element is listed + // in $form_variables under 'op'. + $form_values[$form['#name']] = $form['#value']; } } } @@ -936,7 +946,7 @@ function password_confirm_validate($form) { form_error($form, t('The specified passwords do not match.')); } } - elseif ($form['#required'] && !empty($form['#post']['edit'])) { + elseif ($form['#required'] && !empty($form['#post'])) { form_error($form, t('Password field is required.')); } diff --git a/install.php b/install.php index ba6f223a41f3b05cbbe1c1ee754145908f3b7c80..5431fb71f445fb93bf9fd925b979a0360b317cf1 100644 --- a/install.php +++ b/install.php @@ -354,7 +354,7 @@ function install_select_profile() { } elseif (sizeof($profiles) > 1) { foreach ($profiles as $profile) { - if ($_POST['edit']['profile'] == $profile->name) { + if ($_POST['profile'] == $profile->name) { return $profile->name; } } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 86af8f0b17b601647ea28375f66ee2b05cca484f..80802d8d955175aae92b39b3454b02fc95dadc37 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -939,7 +939,7 @@ function comment_delete($cid) { // We'll only delete if the user has confirmed the // deletion using the form in our else clause below. - if (is_object($comment) && is_numeric($comment->cid) && $_POST['edit']['confirm']) { + if (is_object($comment) && is_numeric($comment->cid) && $_POST['confirm']) { drupal_set_message(t('The comment and all its replies have been deleted.')); // Delete comment and its replies. @@ -1003,7 +1003,7 @@ function comment_operations($action = NULL) { * Menu callback; present an administrative comment listing. */ function comment_admin_overview($type = 'new') { - $edit = $_POST['edit']; + $edit = $_POST; if ($edit['operation'] == 'delete') { return comment_multiple_delete_confirm(); @@ -1117,7 +1117,7 @@ function theme_comment_admin_overview($form) { * them. */ function comment_multiple_delete_confirm() { - $edit = $_POST['edit']; + $edit = $_POST; $form['comments'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); // array_filter() returns only elements with actual values diff --git a/modules/forum/forum.module b/modules/forum/forum.module index ad2cc2c9dee7e702082c4ac1a85e269bf0e5f3c1..fdc06eb172070f0d47b678544f9a5b9fbc1eff98 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -445,7 +445,7 @@ function forum_delete(&$node) { */ function forum_form_container($edit = array()) { // Handle a delete operation. - if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { + if ($_POST['op'] == t('Delete') || $_POST['confirm']) { return forum_confirm_delete($edit['tid']); } @@ -494,7 +494,7 @@ function forum_form_container($edit = array()) { */ function forum_form_forum($edit = array()) { // Handle a delete operation. - if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { + if ($_POST['op'] == t('Delete') || $_POST['confirm']) { return forum_confirm_delete($edit['tid']); } diff --git a/modules/menu/menu.module b/modules/menu/menu.module index e8c41358591b35c5600d2f92feb0ad6466ccc9d9..936bdbd625ba8d1ae8dab235bdc0cd605db130d6 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -188,7 +188,7 @@ function menu_perm() { */ function menu_form_alter($form_id, &$form) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { - $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; + $edit = isset($_POST) ? $_POST : ''; $edit['nid'] = $form['nid']['#value']; $item = array(); diff --git a/modules/node/node.module b/modules/node/node.module index ab12243484e06ddcff1a38fec79f75089680c291..8d5ad794c189367c4dc9c80a98044e90d54be06c 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1427,7 +1427,7 @@ function node_admin_nodes_validate($form_id, $edit) { function node_admin_content() { $output = drupal_get_form('node_filter_form'); - if ($_POST['edit']['operation'] == 'delete' && $_POST['edit']['nodes']) { + if ($_POST['operation'] == 'delete' && $_POST['nodes']) { return drupal_get_form('node_multiple_delete_confirm'); } // Call the form first, to allow for the form_values array to be populated. @@ -1504,7 +1504,7 @@ function theme_node_admin_nodes($form) { } function node_multiple_delete_confirm() { - $edit = $_POST['edit']; + $edit = $_POST; $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); // array_filter returns only elements with TRUE values @@ -1652,7 +1652,7 @@ function node_revision_list($node) { } function node_admin_search() { - return drupal_get_form('search_form', url('admin/content/search'), $_POST['edit']['keys'], 'node') . search_data($_POST['edit']['keys'], 'node'); + return drupal_get_form('search_form', url('admin/content/search'), $_POST['keys'], 'node') . search_data($_POST['keys'], 'node'); } /** @@ -1814,7 +1814,7 @@ function node_validate($node, $form = array()) { form_set_error('body', t('The body of your @type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@type' => $type->name))); } - if (isset($node->nid) && (node_last_changed($node->nid) > $_POST['edit']['changed'])) { + if (isset($node->nid) && (node_last_changed($node->nid) > $_POST['changed'])) { form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.')); } @@ -1947,8 +1947,8 @@ function node_form($node) { function node_form_add_preview($form) { global $form_values; - $op = isset($_POST['op']) ? $_POST['op'] : ''; - if ($op == t('Preview')) { + $op = isset($form_values['op']) ? $form_values['op'] : ''; + if ($op == $form_values['preview']) { drupal_validate_form($form['form_id']['#value'], $form); if (!form_get_errors()) { // We pass the global $form_values here to preserve changes made during form validation @@ -2157,7 +2157,7 @@ function node_form_submit($form_id, $edit) { * Menu callback -- ask for confirmation of node deletion */ function node_delete_confirm() { - $edit = $_POST['edit']; + $edit = $_POST; $edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1); $node = node_load($edit['nid']); diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 1865628870d1e020edb2b83da800dc7559488c47..ddf36ea02a9ca467750ebd9d75357eee0e1bfc7a 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -468,7 +468,7 @@ function poll_vote(&$node) { $nid = arg(1); if ($node = node_load($nid)) { - $edit = $_POST['edit']; + $edit = $_POST; $choice = $edit['choice']; $vote = $_POST['vote']; @@ -513,7 +513,7 @@ function poll_cancel(&$node) { $nid = arg(2); if ($node = node_load(array('nid' => $nid))) { - $edit = $_POST['edit']; + $edit = $_POST; $choice = $edit['choice']; $cancel = $_POST['cancel']; diff --git a/modules/search/search.module b/modules/search/search.module index 8a4573b770b22add10afb4d11b460c677eec6019..7e19593b0444ed5b5b5d6819dbe60e22b7872c89 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -908,7 +908,7 @@ function search_view() { // Search form submits with POST but redirects to GET. This way we can keep // the search query URL clean as a whistle: // search/type/keyword+keyword - if (!isset($_POST['edit']['form_id'])) { + if (!isset($_POST['form_id'])) { if ($type == '') { // Note: search/node can not be a default tab because it would take on the // path of its parent (search). It would prevent remembering keywords when diff --git a/modules/system/system.module b/modules/system/system.module index b9dfe9b13861ab71c9bc39aac6e3bed8eea6ab4d..614e57cc7dbfad01f9004a53e196e0364f053b89 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1359,9 +1359,9 @@ function system_theme_settings($key = '') { $filename = ($key) ? str_replace('/', '_', $key) . '_logo.' . $parts['extension'] : 'logo.' . $parts['extension']; if ($file = file_save_upload('logo_upload', $filename, 1)) { - $_POST['edit']['default_logo'] = 0; - $_POST['edit']['logo_path'] = $file->filepath; - $_POST['edit']['toggle_logo'] = 1; + $_POST['default_logo'] = 0; + $_POST['logo_path'] = $file->filepath; + $_POST['toggle_logo'] = 1; } } else { @@ -1375,9 +1375,9 @@ function system_theme_settings($key = '') { $filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension']; if ($file = file_save_upload('favicon_upload', $filename, 1)) { - $_POST['edit']['default_favicon'] = 0; - $_POST['edit']['favicon_path'] = $file->filepath; - $_POST['edit']['toggle_favicon'] = 1; + $_POST['default_favicon'] = 0; + $_POST['favicon_path'] = $file->filepath; + $_POST['toggle_favicon'] = 1; } } @@ -1523,7 +1523,7 @@ function system_theme_settings($key = '') { * offered to go back to the item that is being changed in case the user changes * his/her mind. * - * You can check for the existence of $_POST['edit'][$name] (where $name + * You can check for the existence of $_POST[$name] (where $name * is usually 'confirm') to check if the confirmation was successful or * use the regular submit model. * diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index cda680893f99ddb32e8f8600f8e9c10d4a492aad..32d38435bef036d064374dac86b5b1f79d1b8ede 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1277,7 +1277,7 @@ function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { * Page to edit a vocabulary */ function taxonomy_admin_vocabulary_edit($vid = NULL) { - if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { + if ($_POST['op'] == t('Delete') || $_POST['confirm']) { return drupal_get_form('taxonomy_vocabulary_confirm_delete', $vid); } if ($vocabulary = (array)taxonomy_get_vocabulary($vid)) { @@ -1290,7 +1290,7 @@ function taxonomy_admin_vocabulary_edit($vid = NULL) { * Page to edit a vocabulary term */ function taxonomy_admin_term_edit($tid) { - if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { + if ($_POST['op'] == t('Delete') || $_POST['confirm']) { return drupal_get_form('taxonomy_term_confirm_delete', $tid); } if ($term = (array)taxonomy_get_term($tid)) { diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 084c2ed40bf7c121919bf025f41007272a9cd719..9db67c4a30e40f333bd88f2943d3227fe8432fe3 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -877,7 +877,7 @@ function _upload_image($file) { */ function upload_js() { // We only do the upload.module part of the node validation process. - $node = (object)$_POST['edit']; + $node = (object)$_POST; // Load existing node files. $node->files = upload_load($node); diff --git a/modules/user/user.module b/modules/user/user.module index eb8825a7930d6585400d6f00e7e3cf153c8a555a..54f279d606bc3f90c0a12fc15b7c937a71edd41a 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1384,7 +1384,7 @@ function user_edit($category = 'account') { drupal_set_message(t('The account does not exist or has already been deleted.')); drupal_goto('admin/user/user'); } - $edit = $_POST['op'] ? $_POST['edit'] : (array)$account; + $edit = $_POST['op'] ? $_POST : (array)$account; if (arg(2) == 'delete') { if ($edit['confirm']) { @@ -1607,7 +1607,7 @@ function user_admin_access_check_submit($form_id, $edit) { * Menu callback: add an access rule */ function user_admin_access_add($mask = NULL, $type = NULL) { - if ($edit = $_POST['edit']) { + if ($edit = $_POST) { if (!$edit['mask']) { form_set_error('mask', t('You must enter a mask.')); } @@ -1653,7 +1653,7 @@ function user_admin_access_delete_confirm_submit($form_id, $edit) { * Menu callback: edit an access rule */ function user_admin_access_edit($aid = 0) { - if ($edit = $_POST['edit']) { + if ($edit = $_POST) { if (!$edit['mask']) { form_set_error('mask', t('You must enter a mask.')); } @@ -1870,7 +1870,7 @@ function user_admin_perm_submit($form_id, $edit) { * Menu callback: administer roles. */ function user_admin_role() { - $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; + $edit = isset($_POST) ? $_POST : ''; $op = isset($_POST['op']) ? $_POST['op'] : ''; $id = arg(4); @@ -1933,7 +1933,7 @@ function theme_user_admin_new_role($form) { } function user_admin_account() { - if ($_POST['edit']['accounts'] && $_POST['edit']['operation'] == 'delete') { + if ($_POST['accounts'] && $_POST['operation'] == 'delete') { return user_multiple_delete_confirm(); } @@ -2168,7 +2168,7 @@ function user_multiple_role_edit($accounts, $operation, $rid) { } function user_multiple_delete_confirm() { - $edit = $_POST['edit']; + $edit = $_POST; $form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE); // array_filter returns only elements with TRUE values @@ -2230,13 +2230,13 @@ function user_admin_settings() { } function user_admin($callback_arg = '') { - $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; + $edit = isset($_POST) ? $_POST : ''; $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg; switch ($op) { case 'search': case t('Search'): - $output = drupal_get_form('search_form', url('admin/user/search'), $_POST['edit']['keys'], 'user') . search_data($_POST['edit']['keys'], 'user'); + $output = drupal_get_form('search_form', url('admin/user/search'), $_POST['keys'], 'user') . search_data($_POST['keys'], 'user'); break; case t('Create new account'): case 'create': diff --git a/update.php b/update.php index 5e4454feec210a50dbe36d301c1eb03c777b31ff..2e9390d08d805416dabad26df0bc7d884ca61d00 100644 --- a/update.php +++ b/update.php @@ -377,7 +377,7 @@ function update_script_selection_form() { function update_update_page() { // Set the installed version so updates start at the correct place. - foreach ($_POST['edit']['start'] as $module => $version) { + foreach ($_POST['start'] as $module => $version) { drupal_set_installed_schema_version($module, $version - 1); $updates = drupal_get_schema_versions($module); $max_version = max($updates); @@ -393,7 +393,7 @@ function update_update_page() { // Keep track of total number of updates $_SESSION['update_total'] = count($_SESSION['update_remaining']); - if ($_POST['edit']['has_js']) { + if ($_POST['has_js']) { return update_progress_page(); } else {