处理节点表单提交之后的页面跳转

  在普通情况下,当用户提交节点表单后会被重定向到对应的节点页面,如果在 URL 中传入了 ?destination=path/xxx 这样的参数,提交表单后用户就会被重定向到 destination 设置的页面。

  除此之外,开发人员还可以通过为节点表单设置重定向属性,来控制表单提交后的重定向路径。

  下面的代码通过应用 hook_form_alter(),判断当表单ID为"story_node_form"时,设置表单的重定向属性(#redirect

<?php
/**
 * Implements hook_form_alter().
 */
function test_form_alter(&$form, &$form_state$form_id) {
  
  if (
$form_id == 'story_node_form') {
  
    
// Your code goes here
    // ...

    // Set a '#redirect' key and value for $form,
    // after users submit the node, they will be redirect to specific path.
    
$form['#redirect'] = 'node';

  }
  
}
?>