Commit bceaf8f0 authored by drumm's avatar drumm
Browse files

#80574 Eaton and chx. Replace $_POST['edit'] with $_POST.

parent ad0e8b56
......@@ -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.'));
}
......
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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']);
}
......
......@@ -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();
......
......@@ -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']);
......
......@@ -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'];
......
......@@ -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
......
......@@ -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.
*
......
......@@ -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)) {
......
......@@ -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);
......
......@@ -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':
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment