1

I have Druapl 6 with orgranic groups installed. I need a thing - when a group user creates "group" content after node form submission he must be redirected back on group homepage instead of node view page.

function heihachi_form_alter(&$form, $form_state, $form_id) {
  switch($form_id) {
        case 'group_wall_node_form':
        unset($form['buttons']['preview']);

        $redirect = 'node/' . $form['og_initial_groups']['#value'][0];
        $form_state['redirect'][0] = $redirect;
        //dpm($form);
        break;
  }
}

but that code doesn't redirect at all. Using simple $form['#redirect'] works, but it affects Node delete button aswell, so i can't delete my node because it redirects on a custom path. Thanks for all advices in advance.

My new code (not working also):

function heihachi_form_alter(&$form, $form_state, $form_id) {
  switch($form_id) {
        case 'group_wall_node_form':
        unset($form['buttons']['preview']);
        $form['#submit'][] = 'custom_redirect';
        //dpm($form);
        break;
  }
}

function custom_redirect($form, &$form_state) {

  //unset($_REQUEST['destination']);
  //unset($form['#redirect']);

  $form_state['rebuild'] = TRUE;

  $redirect = 'node/' . $form['og_initial_groups']['#value'][0];
  $form_state['redirect'] = $redirect;
}

This is what i see in $form variable:

0 (String, 21 characters ) menu_node_form_submit | (Callback) menu_node_form_submit();

1 (String, 31 characters ) auto_nodetitle_node_form_submit | (Callback) auto_nodetitle_node_form_submit();

2 (String, 15 characters ) custom_redirect | (Callback) custom_redirect();

I guess something wrong is there?

SOLVED!

used hook_nodeapi as one guy told me below:

function heihachi_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($node->type == 'group_wall') {
    if ($op == 'insert') {
      $_REQUEST['destination'] = 'xxx';
    }
  }
3

1 Answer 1

2

use hook_nodeapi with op insert or add another submit function in hook_form_alter.

4
  • 1
    Adding a new submission function, IMO, is the best way. nodeapi hooks are somewhat expensive (you alter the form anyway so why hook again ?). Do NOT use drupal_got() in forms! Use $form_state['redirect'] instead. Also, it's better $form['buttons']['preview']['#access'] = FALSE; than unsetting it.
    – AKS
    Commented Dec 12, 2012 at 14:09
  • Thanks, $form_state['redirect'] is not working for me somehow... Commented Dec 12, 2012 at 16:19
  • @Heihachi I think you should write $form_state['redirect'] in submit function. Commented Dec 12, 2012 at 16:51
  • Check my updated post please Commented Dec 12, 2012 at 17:26

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.