Drupal - Use hook_form_alter() to set redirect path on the form

One popular use of this hook is to change the destination of a form submission. Here is how it is accomplished:

<?php
function YOURMODULE_form_alter($form_id, &$form) {
  switch ($form['#id']) {
    case 'node-form':
       if ($form['type']['#value'] == 'story') {
         $form['#redirect'] = 'new/url';
       }
     break;
  }
}
?>

1 comments for Drupal - Use hook_form_alter() to set redirect path on the form

Brian's picture

Again another piece of useful...

Again another piece of useful code. it's so hard to find good documentation for Drupal.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.