I have an embedded view set up showing articles one by one, with comments beneath them - and comment form on the same page - crucial for this site, its "main" feature. Drupal version 6.14 here.

Of course, this is not the "main" node page for these comments - so default behavior of the comments module is to redirect to the page, thus losing the position one's in in the view pager.

What I need is for comments to redirect back to the article on in the view, on the page the user came from.

I have tried this a number of ways. Simply changing $form['#action'] does bring the user back to the correct page, but somehow the comment is not posted, and does not appear either in the view, nor on the node page of the article.

I have tried altering $form['#redirect'], which does nothing. The comments module has code at line #1547 in comment_form_submit() modifiying $form_state['redirect'], which is perhaps why this does nothing.

Because of this occurs in the submit function, I tried altering the $form['#submit'] array - replacing the element 'comment_form_submit' with a custom callback submit function. This also appears to do nothing, as when I die('somestring'), comments are simply saved as usual - indicating the custom callback submit function has not been called.

I have been brainstorming, thinking also of checking in the template of the article for $_POST values in which I'd insert the url to redirect to, redirecting then with a javascript redirect ... but of course, this wouldn't come through, as the node is only arrived at via a redirect.

I'm nearly at the point of creating my own module with its own form which would save the comment with comment_save(), which I'm already doing with comments which are allowed to be submitted through an off-site service. But quite a lot of effort just to get the user redirected to the right page!

Any insights here as to how I could do this more efficiently, or what I could possibly be doing wrong?

Comments

jmcoder’s picture

I think that what I'll do here is simply set a $_SESSION var (or maybe a user var) inside hook_form_alter under the appropriate conditions, and then check for this var, delete it, and use it to redirect with hook_nodeapi on the content type in question. Nonetheless, this may only be a temporary solution, and I welcome your thoughts about the problem I sketched out above.

- > not easy since one must also detect that a comment has actually been posted - and we don't have access to the functions which are doing this in order to flag that the comment being posted was from the article in question here.

jevets’s picture

Not sure if I'll be much help here, but did you try altering $form_submit['redirect'] in addition to $form['#redirect']?

jmcoder’s picture

Thanks Steve, I'm guessing you mean $form_state as i's one of the variables in hook_form_alter? I did try that as well. I'll try it again and update this comment.

UPDATE:
No joy - didn't think it would either, as I'd tried it before against all hope - but $form_state is NOT passed by reference in hook_form_alter - I added the & to mine sort of crossing my fingers that this might work, but as expected it's not working - the calling function won't be passing it by reference either.

jevets’s picture

Have you tried hooking into comment_form_submit() to set the #redirect?

hook_comment_form_submit()