Redirect after node creation

Public

If you want to redirect your user to another page, than the default the newly created node.

Get raw version
php
  1. /**
  2.  * Implements hook_form_alter().
  3.  */
  4. function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  5. // Replace NODETYPE with the systemname of your node type.
  6. if ($form_id == 'NODETYPE_node_form') {
  7. $form['actions']['submit']['#submit'][] = 'MYMODULE_node_submit';
  8. }
  9. }
  10.  
  11. /**
  12.  * Custom submit function.
  13.  *
  14.  * Redirect user to the site frontpage after node creation.
  15.  */
  16. function MYMODULE_node_submit($form, &$form_state) {
  17. $form_state['redirect'] = variable_get('site_frontpage', 'node');
  18. }

Comments

danylevskyi's picture

There is a missing argument for hook_form_alter().