Commit 583d5a4e authored by Dries's avatar Dries

- Patch #48622 by adrian: remove drupal_goto from _submit functions.

parent 91152ba7
......@@ -1193,7 +1193,7 @@ function drupal_to_js($var) {
}
return '[ '. implode(', ', $output) .' ]';
}
// Fall through
// Fall through
case 'object':
$output = array();
foreach ($var as $k => $v) {
......
......@@ -103,11 +103,24 @@ function drupal_get_form($form_id, &$form, $callback = NULL) {
}
$form = _form_builder($form_id, $form);
$goto = $_GET['q'];
if (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $callback))) {
drupal_validate_form($form_id, $form, $callback);
if ($form_submitted && !form_get_errors()) {
drupal_submit_form($form_id, $form, $callback);
$redirect = drupal_submit_form($form_id, $form, $callback);
if (!is_null($redirect)) {
$goto = $redirect;
}
else if ($form['#redirect']) {
$goto = $form['#redirect'];
}
if (is_array($goto)) {
call_user_func_array('drupal_goto', $redirect);
}
else {
drupal_goto(drupal_get_path_alias($goto));
}
}
}
......@@ -136,14 +149,18 @@ function drupal_validate_form($form_id, &$form, $callback = NULL) {
function drupal_submit_form($form_id, $form, $callback = NULL) {
global $form_values;
$goto = null;
unset($GLOBALS['form_values']['submit'], $GLOBALS['form_values']['form_id']);
if (isset($form['#submit'])) {
foreach ($form['#submit'] as $function => $args) {
if (function_exists($function)) {
call_user_func_array($function, $args);
// Since we can only redirect to one page, only the last redirect will work
$redirect = call_user_func_array($function, $args);
$goto = (!is_null($redirect)) ? $redirect : $goto;
}
}
}
return $goto;
}
function _form_validate($elements, $form_id = NULL) {
......
......@@ -998,8 +998,8 @@ function _menu_sort($a, $b) {
elseif ($a['weight'] > $b['weight']) {
return 1;
}
elseif (isset($a['title']) && isset($b['title']) && ($a['title'] < $b['title'])) {
return -1;
elseif (isset($a['title']) && isset($b['title'])) {
return strnatcasecmp($a['title'], $b['title']);
}
else {
return 1;
......
......@@ -291,7 +291,20 @@ tr.odd .form-item, tr.even .form-item {
#forum td.posts, #forum td.topics, #forum td.replies, #forum td.pager {
text-align: center;
}
.forum-topic-navigation {
padding: 1em 0 0 3em;
border-top: 1px solid #888;
border-bottom: 1px solid #888;
text-align: center;
padding: 0.5em;
}
.forum-topic-navigation .topic-previous {
margin-right: 4em;
text-align: right;
}
.forum-topic-navigation .topic-next {
text-align: left;
}
.locale-untranslated {
font-style: normal;
text-decoration: line-through;
......
......@@ -1013,7 +1013,6 @@ function aggregator_page_list_submit($form_id, $form) {
}
}
drupal_set_message(t('The categories have been saved.'));
drupal_goto($_GET['q']);
}
......
......@@ -1013,7 +1013,6 @@ function aggregator_page_list_submit($form_id, $form) {
}
}
drupal_set_message(t('The categories have been saved.'));
drupal_goto($_GET['q']);
}
......
......@@ -406,7 +406,7 @@ function block_admin_configure_submit($form_id, $form_values) {
module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
drupal_goto('admin/block');
return 'admin/block';
}
}
......@@ -430,7 +430,7 @@ function block_box_add_submit($form_id, $form_values) {
if (!form_get_errors()) {
if (block_box_save($form_values)) {
drupal_set_message(t('The block has been created.'));
drupal_goto('admin/block');
return 'admin/block';
}
}
}
......@@ -453,7 +453,7 @@ function block_box_delete_confirm_submit($form_id, $form_values) {
db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);
drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info']))));
cache_clear_all();
drupal_goto('admin/block');
return 'admin/block';
};
function block_box_form($edit = array()) {
......
......@@ -406,7 +406,7 @@ function block_admin_configure_submit($form_id, $form_values) {
module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
drupal_goto('admin/block');
return 'admin/block';
}
}
......@@ -430,7 +430,7 @@ function block_box_add_submit($form_id, $form_values) {
if (!form_get_errors()) {
if (block_box_save($form_values)) {
drupal_set_message(t('The block has been created.'));
drupal_goto('admin/block');
return 'admin/block';
}
}
}
......@@ -453,7 +453,7 @@ function block_box_delete_confirm_submit($form_id, $form_values) {
db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);
drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info']))));
cache_clear_all();
drupal_goto('admin/block');
return 'admin/block';
};
function block_box_form($edit = array()) {
......
......@@ -1413,7 +1413,7 @@ function _comment_form_submit($form_values) {
function comment_form_submit($form_id, $form_values) {
$form_values = _comment_form_submit($form_values);
if ($cid = comment_save($form_values)) {
drupal_goto('node/'. $form_values['nid'], NULL, "comment-$cid");
return array('node/'. $form_values['nid'], NULL, "comment-$cid");
}
}
......
......@@ -1413,7 +1413,7 @@ function _comment_form_submit($form_values) {
function comment_form_submit($form_id, $form_values) {
$form_values = _comment_form_submit($form_values);
if ($cid = comment_save($form_values)) {
drupal_goto('node/'. $form_values['nid'], NULL, "comment-$cid");
return array('node/'. $form_values['nid'], NULL, "comment-$cid");
}
}
......
......@@ -199,7 +199,7 @@ function contact_mail_user_submit($form_id, $edit) {
drupal_set_message(t('The message has been sent.'));
// Jump to the user's profile page:
drupal_goto("user/$account->uid");
return "user/$account->uid";
}
function contact_admin_edit($cid = NULL) {
......@@ -285,7 +285,7 @@ function contact_admin_edit_submit($form_id, $form_values) {
db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid=%d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);
}
drupal_set_message(t('Category %category has been updated.', array('%category' => theme('placeholder', $edit['category']))));
drupal_goto('admin/contact');
return 'admin/contact';
}
function contact_admin_delete($cid) {
......@@ -453,5 +453,5 @@ function contact_mail_page_submit($form_id, $edit) {
drupal_set_message(t('Your message has been sent.'));
// Jump to contact page:
drupal_goto('contact');
return 'contact';
}
......@@ -199,7 +199,7 @@ function contact_mail_user_submit($form_id, $edit) {
drupal_set_message(t('The message has been sent.'));
// Jump to the user's profile page:
drupal_goto("user/$account->uid");
return "user/$account->uid";
}
function contact_admin_edit($cid = NULL) {
......@@ -285,7 +285,7 @@ function contact_admin_edit_submit($form_id, $form_values) {
db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid=%d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);
}
drupal_set_message(t('Category %category has been updated.', array('%category' => theme('placeholder', $edit['category']))));
drupal_goto('admin/contact');
return 'admin/contact';
}
function contact_admin_delete($cid) {
......@@ -453,5 +453,5 @@ function contact_mail_page_submit($form_id, $edit) {
drupal_set_message(t('Your message has been sent.'));
// Jump to contact page:
drupal_goto('contact');
return 'contact';
}
......@@ -1093,7 +1093,7 @@ function node_filter_form_submit() {
return;
}
if ($op != '') {
drupal_goto('admin/node');
return 'admin/node';
}
}
......@@ -1111,7 +1111,7 @@ function node_admin_nodes_submit($form_id, $edit) {
}
}
drupal_set_message(t('The update has been performed.'));
drupal_goto('admin/node');
return 'admin/node';
}
}
......@@ -1227,7 +1227,7 @@ function node_multiple_delete_confirm_submit($form_id, $edit) {
}
drupal_set_message(t('The items have been deleted.'));
}
drupal_goto('admin/node');
return 'admin/node';
}
/**
......@@ -1865,14 +1865,8 @@ function node_form_submit($form_id, $edit) {
drupal_set_message(t('Your %post was created.', array ('%post' => node_get_name($node))));
}
}
if ($node->nid) {
if (node_access('view', $node)) {
drupal_goto('node/'. $node->nid);
}
else {
drupal_goto();
}
if ($node->nid && node_access('view', $node)) {
return 'node/'. $node->nid;
}
}
......@@ -1901,7 +1895,6 @@ function node_delete_confirm() {
function node_delete_confirm_submit($form_id, $form_values) {
if ($form_values['confirm']) {
node_delete($form_values['nid']);
drupal_goto();
}
}
......
......@@ -1093,7 +1093,7 @@ function node_filter_form_submit() {
return;
}
if ($op != '') {
drupal_goto('admin/node');
return 'admin/node';
}
}
......@@ -1111,7 +1111,7 @@ function node_admin_nodes_submit($form_id, $edit) {
}
}
drupal_set_message(t('The update has been performed.'));
drupal_goto('admin/node');
return 'admin/node';
}
}
......@@ -1227,7 +1227,7 @@ function node_multiple_delete_confirm_submit($form_id, $edit) {
}
drupal_set_message(t('The items have been deleted.'));
}
drupal_goto('admin/node');
return 'admin/node';
}
/**
......@@ -1865,14 +1865,8 @@ function node_form_submit($form_id, $edit) {
drupal_set_message(t('Your %post was created.', array ('%post' => node_get_name($node))));
}
}
if ($node->nid) {
if (node_access('view', $node)) {
drupal_goto('node/'. $node->nid);
}
else {
drupal_goto();
}
if ($node->nid && node_access('view', $node)) {
return 'node/'. $node->nid;
}
}
......@@ -1901,7 +1895,6 @@ function node_delete_confirm() {
function node_delete_confirm_submit($form_id, $form_values) {
if ($form_values['confirm']) {
node_delete($form_values['nid']);
drupal_goto();
}
}
......
......@@ -117,7 +117,7 @@ function path_admin_delete_confirm($pid) {
function path_admin_delete_confirm_submit($form_id, $form_values) {
if ($form_values['confirm']) {
path_admin_delete($form_values['pid']);
drupal_goto('admin/path');
return 'admin/path';
}
}
......@@ -342,7 +342,7 @@ function path_form_submit() {
path_set_alias($src, $dst, $pid);
drupal_set_message(t('The alias has been saved.'));
drupal_goto('admin/path');
return 'admin/path';
}
}
......
......@@ -117,7 +117,7 @@ function path_admin_delete_confirm($pid) {
function path_admin_delete_confirm_submit($form_id, $form_values) {
if ($form_values['confirm']) {
path_admin_delete($form_values['pid']);
drupal_goto('admin/path');
return 'admin/path';
}
}
......@@ -342,7 +342,7 @@ function path_form_submit() {
path_set_alias($src, $dst, $pid);
drupal_set_message(t('The alias has been saved.'));
drupal_goto('admin/path');
return 'admin/path';
}
}
......
......@@ -245,7 +245,7 @@ function search_wipe_confirm_submit($form_id, &$form) {
if ($form['confirm']) {
search_wipe();
drupal_set_message(t('The index will be rebuilt.'));
drupal_goto('admin/settings/search');
return 'admin/settings/search';
}
}
......
......@@ -245,7 +245,7 @@ function search_wipe_confirm_submit($form_id, &$form) {
if ($form['confirm']) {
search_wipe();
drupal_set_message(t('The index will be rebuilt.'));
drupal_goto('admin/settings/search');
return 'admin/settings/search';
}
}
......
......@@ -55,7 +55,7 @@ function system_perm() {
*/
function system_elements() {
// Top level form
$type['form'] = array('#method' => 'post', '#action' => request_uri());
$type['form'] = array('#method' => 'post', '#action' => request_uri(), '#redirect' => '');
// Inputs
$type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
......@@ -787,7 +787,6 @@ function system_settings_form_submit($form_id, $values) {
drupal_set_message(t('The configuration options have been saved.'));
}
menu_rebuild();
drupal_goto($_GET['q']);
}
/**
......@@ -887,7 +886,7 @@ function system_themes_submit($form_id, $values) {
menu_rebuild();
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/themes');
return 'admin/themes';
}
/**
......@@ -1021,7 +1020,7 @@ function system_modules_submit($form_id, $edit) {
}
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/modules');
return 'admin/modules';
}
......
......@@ -55,7 +55,7 @@ function system_perm() {
*/
function system_elements() {
// Top level form
$type['form'] = array('#method' => 'post', '#action' => request_uri());
$type['form'] = array('#method' => 'post', '#action' => request_uri(), '#redirect' => '');
// Inputs
$type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
......@@ -787,7 +787,6 @@ function system_settings_form_submit($form_id, $values) {
drupal_set_message(t('The configuration options have been saved.'));
}
menu_rebuild();
drupal_goto($_GET['q']);
}
/**
......@@ -887,7 +886,7 @@ function system_themes_submit($form_id, $values) {
menu_rebuild();
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/themes');
return 'admin/themes';
}
/**
......@@ -1021,7 +1020,7 @@ function system_modules_submit($form_id, $edit) {
}
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/modules');
return 'admin/modules';
}
......
......@@ -895,9 +895,6 @@ function user_login_submit($form_id, $form_values) {
db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $user->uid);
user_module_invoke('login', $form_values, $user);
// Redirect the user to the page he logged on from.
drupal_goto();
}
}
......@@ -1012,7 +1009,7 @@ function user_pass_submit($form_id, $form_values) {
watchdog('user', t('Error mailing password reset instructions to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
}
drupal_goto('user');
return 'user';
}
function theme_user_pass($form) {
......@@ -1135,7 +1132,7 @@ function user_register_submit($form_id, $form_values) {
if (!$admin && array_intersect(array_keys($form_values), array('uid', 'roles', 'init', 'session', 'status'))) {
watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING);
drupal_goto('user/register');
return 'user/register';
}
$account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'status' => ($admin || variable_get('user_register', 1) == 1))));
......@@ -1153,13 +1150,13 @@ function user_register_submit($form_id, $form_values) {
include_once './includes/install.inc';
drupal_set_installed_schema_version('system', max(drupal_get_schema_versions('system')));
drupal_goto('user/1/edit');
return 'user/1/edit';
}
else {
if ($admin) {
drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
drupal_goto('admin/user');
return 'admin/user';
}
else if ($account->status) {
// Create new user account, no administrator approval required.
......@@ -1168,7 +1165,6 @@ function user_register_submit($form_id, $form_values) {
user_mail($mail, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
drupal_goto();
}
else {
// Create new user account, administrator approval required.
......@@ -1179,7 +1175,6 @@ function user_register_submit($form_id, $form_values) {
user_mail(variable_get('site_mail', ini_get('sendmail_from')), $subject, t("%u has applied for an account.\n\n%uri", array('%u' => $account->name, '%uri' => url("user/$account->uid/edit", NULL, NULL, TRUE))), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address.'));
drupal_goto();
}
}
}
......@@ -1328,7 +1323,7 @@ function user_edit_submit($form_id, $form_values) {
// Delete that user's menu cache.
cache_clear_all('menu:'. $account->uid, TRUE);
drupal_set_message(t('The changes have been saved.'));
drupal_goto('user/'. $account->uid);
return 'user/'. $account->uid;
}
function user_view($uid = 0) {
......@@ -1497,7 +1492,7 @@ function user_admin_access_delete($aid = 0) {
function user_admin_access_delete_confirm_submit($form_id, $edit) {
db_query('DELETE FROM {access} WHERE aid = %d', $edit['aid']);
drupal_set_message(t('The access rule has been deleted.'));
drupal_goto('admin/access/rules');
return 'admin/access/rules';
}
/**
......@@ -1705,7 +1700,6 @@ function user_admin_perm_submit($form_id, $edit) {
// Clear the cached pages and menus:
menu_rebuild();
drupal_goto($_GET['q']);
}
/**
......
......@@ -895,9 +895,6 @@ function user_login_submit($form_id, $form_values) {
db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $user->uid);
user_module_invoke('login', $form_values, $user);
// Redirect the user to the page he logged on from.
drupal_goto();
}
}
......@@ -1012,7 +1009,7 @@ function user_pass_submit($form_id, $form_values) {
watchdog('user', t('Error mailing password reset instructions to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
}
drupal_goto('user');
return 'user';
}
function theme_user_pass($form) {
......@@ -1135,7 +1132,7 @@ function user_register_submit($form_id, $form_values) {
if (!$admin && array_intersect(array_keys($form_values), array('uid', 'roles', 'init', 'session', 'status'))) {
watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING);
drupal_goto('user/register');
return 'user/register';
}
$account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'status' => ($admin || variable_get('user_register', 1) == 1))));
......@@ -1153,13 +1150,13 @@ function user_register_submit($form_id, $form_values) {
include_once './includes/install.inc';
drupal_set_installed_schema_version('system', max(drupal_get_schema_versions('system')));
drupal_goto('user/1/edit');
return 'user/1/edit';
}
else {
if ($admin) {
drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
drupal_goto('admin/user');
return 'admin/user';
}
else if ($account->status) {
// Create new user account, no administrator approval required.
......@@ -1168,7 +1165,6 @@ function user_register_submit($form_id, $form_values) {
user_mail($mail, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
drupal_goto();
}
else {
// Create new user account, administrator approval required.
......@@ -1179,7 +1175,6 @@ function user_register_submit($form_id, $form_values) {
user_mail(variable_get('site_mail', ini_get('sendmail_from')), $subject, t("%u has applied for an account.\n\n%uri", array('%u' => $account->name, '%uri' => url("user/$account->uid/edit", NULL, NULL, TRUE))), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address.'));
drupal_goto();
}
}
}
......@@ -1328,7 +1323,7 @@ function user_edit_submit($form_id, $form_values) {
// Delete that user's menu cache.
cache_clear_all('menu:'. $account->uid, TRUE);
drupal_set_message(t('The changes have been saved.'));
drupal_goto('user/'. $account->uid);
return 'user/'. $account->uid;
}
function user_view($uid = 0) {
......@@ -1497,7 +1492,7 @@ function user_admin_access_delete($aid = 0) {
function user_admin_access_delete_confirm_submit($form_id, $edit) {
db_query('DELETE FROM {access} WHERE aid = %d', $edit['aid']);
drupal_set_message(t('The access rule has been deleted.'));
drupal_goto('admin/access/rules');
return 'admin/access/rules';
}
/**
......@@ -1705,7 +1700,6 @@ function user_admin_perm_submit($form_id, $edit) {
// Clear the cached pages and menus:
menu_rebuild();
drupal_goto($_GET['q']);
}
/**
......
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