0

When I create a new node in my website, I want to be redirect to the edit page of the new node. I see several hook, but according to this post its not possible use drupal_goto..

Is there a way for me ? I prefer a programming approach Thanks =)

1 Answer 1

2

In a custom module, use this code, and don't forget to replace MYMODULE_ with your module machine name :

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'my_content_type_node_form': // Replace my_content_type with yours
      $form['#submit'] = array_merge(array('MYMODULE_my_content_type_node_form_submit'), $form['#submit']);
    break;
}

function MYMODULE_my_content_type_node_form_submit(&$form, &$form_state) {
  $initial_values = $form_state['build_info']['args'][0];
  $form_state['redirect'][] = drupal_get_destination();
  $form_state['redirect'][] = array('destination' => 'node/' . $initial_values->nid . '/edit');

  unset($_GET['destination']);
  $_GET['destination'] = 'node/' . $initial_values->nid . '/edit';
  drupal_static_reset('drupal_get_destination');
  drupal_get_destination();
}
2
  • Thanks for help =) But the nid in 'values' is null :/ ($values['nid'] = null) Commented Jan 7, 2015 at 13:34
  • I've edited my code, retry with the new one Commented Jan 7, 2015 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.