Drupal how to redirect a node form after submitting the form

In Drupal 7, when I send a node message, I redirect to the created node.

I am looking for a redirect to the admin main page when I placed node correctly.

I tried putting this on template.php:

function node_submit($form, &$form_state) { $form_state['redirect'] = 'admin'; } 

But there was an error sending:

Fatal error: unable to update node_submit () (previously declared in / var / www / XXX / modules / node / node.module: 1004) in / var / www / XXX / sites / all / themes / XXX / template.php on the line xx

+4
source share
6 answers

If all you want to do is change where the user redirects after submitting the node form from a specific link, there is a much simpler way.

Just make the link like this:

 /node/add/[CONTENT-TYPE]?destination=[URL-REDIRECT] 

Here is an example I got:

 /node/add/ic-competencies-toolkit-codes?destination=admin/survey-codes 
+6
source

This worked for me:

 function mymodule_form_FORM_ID_alter(&$form, $form_state){ $form['actions']['submit']['#submit'][] = 'mymodule_redirect_callback'; } function mymodule_redirect_callback($form, &$form_state){ $form_state['redirect'] = '_path_'; } 

It is important to note the following:

 $form['actions']['submit']['#submit'][] = 'some_function'; 

will work but

 $form['#submit'][] = 'some_function'; 

will not

+5
source

You can use hook_form_alter () to do this.

 function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) { if ($form_id == "CONTENT_TYPE_node_form") { $form['#redirect'] = "node"; } } 

Hope this works.

+4
source

Alternatively, if you do not want to write code, try the rules module: http://drupal.org/project/rules

Add a new rule and set React on Event to After Saving New Content.

Define the action: "System: page redirection" and fill in the fields accordingly.

If you want to get this rule into code, they can be exported to a module!

+3
source

In Drupal 7, this is the correct way:

 function mymodule_form_alter(&$form, &$form_state, $form_id) { if($form_id === 'myform_id'){ $form['#submit'][] = '_mymodule_redirect_callback'; } function _mymodule_redirect_callback($form, &$form_state) { $form_state['redirect'] = 'http://www.google.ch'; } 
+1
source

The easiest way to redirect a comment form or node form

 case 'my_node_form': $form['#action'] .= '?destination=well-done'; break; 

Pay attention to "." after $ form ['# action']

You need to add no replacement!

+1
source

Source: https://habr.com/ru/post/1415555/


All Articles