Hiya,
Just very very quickly made this extension over here which allows you to re-direct a comment form after a successful comment submission. At the moment though as you can see I have had to add in a hidden field to the comment submission form to allow for a return_url=”“ to be set.
<input type="hidden" name="return_url" value="/template_group/template_name/{segment_3}" />
so this will basically take you to a new template upon a comment submission and adds in the current url_title (in this case segment_3) to the URL.
I’m just wondering now though if there’s any possible way of adding in a new parameter to the comment form tag either by an extension or some other method so that you could instead have something like this :
{exp:comment:form preview="{my_template_group}/comment_preview" return_url="tests/index"}
Comment form fields go in here
{/exp:comment:form}
Note the added return_url=”tests/index” parameter in the ExpressionEngine tag. Just wondering if it’s somehow possible to get hold of this information in any way at all?
Thanks in advance for any information on this one. Good or bad news is both welcome as at least then I will know whether I should carry on along the route I am currently taking or if there might be a better way to do this.
Best wishes,
Mark
I would probably suggest a slightly different approach.
The “official” redirect destination of the comment form can be found in a hidden input:
<input name="RET" value="http://someurl.here/foo/bar/" type="hidden" />
Why not replace that hidden input with the desired URL and let EE do the redirection? OK, that would mean to slightly rework your extension but it will achieve your goal, I think.
Suggestion:
2. Use your desired parameter in the comment:form-tag.
{exp:comment:form preview="{my_template_group}/comment_preview" return_url="tests/index"}
function Comment_redirect_function($hidden_fields) {
global $FNS, $EXT, $TMPL;
if ($EXT->last_call !== FALSE)
{
$hidden_fields = $EXT->last_call;
}
// fetch your custom parameter
$return_url = $TMPL->fetch_param("return_url");
// build the return URL like you did before
$return_url = $FNS->create_url($return_url);
// repalce the value of the hidden RET field
$hidden_fields['RET'] = $return_url;
// return the hidden fields
return $hidden_fields;
}
Hi Oliver,
Thanks for that code. Seems to be getting me somewhere definitely. Just wondering why when I tried to use the fetch_param previously it didn’t return anything to me. I did try that first in my extension but couldn’t get the parameter sent into the extension at all. Is that because it’s now a different hook that it can do this? I’m suspecting that isn’t the case although I did code it exactly the same as you have done above to try and fetch the return_url parameter but it just would never get sent into the extension for some reason which was strange.
What you have shown there seems like it is losing a few of the hidden fields that would normally get created such as entry_id, ACT, URI and PRV but I’m pretty sure I should be able to get those into it on my own so thanks heaps for showing me that. I’d actually never seen that hook before or perhaps had seen it but wasn’t really too sure what it was for so thanks for the heads up on that one.
Best wishes,
Mark
Hi Oliver, Thanks for that code. Seems to be getting me somewhere definitely. Just wondering why when I tried to use the fetch_param previously it didn’t return anything to me. I did try that first in my extension but couldn’t get the parameter sent into the extension at all. Is that because it’s now a different hook that it can do this? I’m suspecting that isn’t the case although I did code it exactly the same as you have done above to try and fetch the return_url parameter but it just would never get sent into the extension for some reason which was strange.
The context in which the “insert_comment_end” hook is executed has nothing to do with template parsing. It is fired by an action request in the url. The $TMPL object is not available there at all.
So your first guess is correct.
What you have shown there seems like it is losing a few of the hidden fields that would normally get created such as entry_id, ACT, URI and PRV but I’m pretty sure I should be able to get those into it on my own so thanks heaps for showing me that.
I cannot replicate that behaviour.
example output with extension enabled:
<input name="ACT" value="1" type="hidden">
<input name="RET" value="http://localhost/ee16/index.php/foo/" type="hidden">
<input name="URI" value="/site/comments/better_title/" type="hidden">
<input name="PRV" value="site/comment_preview" type="hidden">
<input name="XID" value="5f5b45eece8dd855bb73d42babaab8f5711277ec" type="hidden">
<input name="entry_id" value="93" type="hidden">
<input name="site_id" value="1" type="hidden">
example output with extension disabled:
<input name="ACT" value="1" type="hidden">
<input name="RET" value="http://localhost/ee16/index.php/site/comments/better_title/" type="hidden">
<input name="URI" value="/site/comments/better_title/" type="hidden">
<input name="PRV" value="site/comment_preview" type="hidden">
<input name="XID" value="f39cc507cd57bf8e01f0f57147b0372f8e97a914" type="hidden">
<input name="entry_id" value="93" type="hidden">
<input name="site_id" value="1" type="hidden">
Any chance you got another extension installed which uses the same hook and doesn’t return all fields?
Any chance you got another extension installed which uses the same hook and doesn’t return all fields?
Hmm that’s odd. Nope no other extensions with that same hook but I will try on a brand new install of 1.6.7 to see what happens. Thanks for the heads up though and thanks for the help on this.
Best wishes,
Mark
Hmm very weird. Not sure why it’s not working for me. Just installed a brand new version of 1.6.7 on a localhost and I get this with the extension installed :
<div class='hiddenFields'>
<input type="hidden" name="XID" value="92db0ab2a2520f2cd9afa6911234e14aefef3d3b" />
<input type="hidden" name="RET" value="http://localhost:8888/ee167/index.php/site/new-comments/" />
<input type="hidden" name="site_id" value="1" />
</div>
This without it installed :
<div class='hiddenFields'>
<input type="hidden" name="ACT" value="1" />
<input type="hidden" name="RET" value="http://localhost:8888/ee167/index.php/site/comments/getting_started/" />
<input type="hidden" name="URI" value="/site/comments/getting_started/" />
<input type="hidden" name="PRV" value="site/comment_preview" />
<input type="hidden" name="XID" value="546346b248d5ce89f648e3d143f531223697236e" />
<input type="hidden" name="entry_id" value="1" />
<input type="hidden" name="site_id" value="1" />
</div>
Not too sure where I’m going wrong on this one. Possibly something in my extension file I guess although I’m pretty certain I haven’t mucked up on that as I pretty much just placed your code from above into my function that gets run when that hook is called.
I’m going to re-write the extension and leave all the nitty bitty stuff out as I have copied a few coding conventions from elsewhere. Will let you know how I get on with it.
Best wishes,
Mark
Hmm, the “XID” and “site_id” will be there even when your method returns nothing at all, so it seems as if there is some kind of glitch in your function.
Do you pick up the hidden_fields array in your function’s argument list at all?
Comment_redirect_function($hidden_fields)
If not, it’d explain the result you’re getting.
Hmm, the “XID” and “site_id” will be there even when your method returns nothing at all, so it seems as if there is some kind of glitch in your function. Do you pick up the hidden_fields array in your function’s argument list at all? Comment_redirect_function($hidden_fields) If not, it’d explain the result you’re getting.
Yep that would explain it wouldn’t it 😉
Thanks Oliver, that seems to have done it. I actually had for some reason the function in my PHP file twice. Was copying some method of creating an extension from one of the other developers add-ons. I had placed the $hidden_fields part in the wrong place!! Don’t I feel like a dolt now!!
Thanks again. Off to test this thing out fully now!
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.