I'm trying to do something simple here and I can't get the form to listen to me...probably me. But need a hand.

I have a guestbook node type...thus a guestbook entry form as well. They are both being displayed on a panel page with form block and views (form via formblock, nodes via views).

It's a fairly simple setup...and works well. Except when I submit my form, it takes me to the node page after creation, instead of staying on the same panel page.

So, I assumed I could affect this with the following code:
custom module named "hh_forms".


function hh_forms_form_alter(&$form, $form_state, $form_id) {
  //dpr($form_id);
 
	switch ($form_id) {
    case 'guestbook_entry_node_form':
    	
	$form['#redirect'] = 'guestbook';
    	
      break;
  }
}

But nothing happens, I've used devel to check that I've gotten the right form and I can cause the form to die and print out various statements, so I know my switch statement is right, but why would the form not redirect. If you would like to have a look at the example...please go to http:www.hylenskihammock.com/new/guestbook.

Anonymous users can add entries..., while I test this...the preview functionality works well and it submits just fine, but I can't get it to redirect properly. I have the devel module loaded, so you can have a look at the code. Please let me know if you have any tips.

Thanks

Comments

nedjo’s picture

The reason is in http://api.drupal.org/api/function/node_form_submit/6:


    $form_state['redirect'] = 'node/'. $node->nid;

The submit handler sets the redirect, and so overwrites what you did in form_alter().

Suggested approach: In form_alter() register a #submit callback and set #redirect there. If that doesn't work (because some other module is interfering), you could resort to setting $_REQUEST['destination'] = 'guestbook';

bhylenski’s picture

I'm not sure why...maybe you could enlighten, as well. But, just before i recieved your message I tried disabling the redirect that ajax does using the Ajax plugin "disable redirect." That seem to do the job. Now, my form is handled via ajax and I used "ajax views refresh" to refresh my view on the left panel. Seems to work flawlessly....but based on what you said above, why is this working? Does the ajax module work on the $form_state parameter?

Bilmar’s picture

subscribing. I am interested in learning more about the solution so that I may implement this on my website as well.
Thanks very much in advance!

robby.smith’s picture

subscribing

mikey_p’s picture

Status: Active » Closed (won't fix)

Closing out old 6.x issues.