I want to issue a sql statement in php after a successful comment posting but can’t figure out where to do that. Both the $IN and $OUT variables do not have enough information, as well as the $_POST values are empty when the page comes back online. I have been editing the blog/detail template, which is used to show the individual blog post and the comments. The return parameter is ignored in the statement below. {exp:comment:form weblog=“blog” preview=“blog/detail”}
To restate: EE is saving the comment correctly, and reloading the detail page with the new comment.
I want to issue a sql statement via php when the comment is saved to the db, and not upon each page load.
Anyone have any ideas on how to go about this?
thanks
Moved to Extensions: Technical Assistance by Moderator
Sorry if I wasn’t clear.
I want to issue a sql query after a comment is posted. I can’t find a way to test for a successful comment submission condition in the blog detail template.
Here is the process:
I want to place a piece of code on the blog details page, that will only run when a new comment is posted, on step 3.
I have tried to trap/test for any $_POST variables, but they are blank after the blog details page reloads with the new comment in step 3. I have also checked the $IN variables, and I can’t find any method to determine if the blog details page is loading as in step 1 or in step 3 (a result of a comment being submitted/saved)
Can anyone point me in the right direction for adding an post comment submission function?
thanks
Thanks for the move.
I guess I have more questions.
Is it possible to call this hook from a template, the blog/detail template in particular? How?
Do I need to modify the mod.comment.php to edit this hook? I am missing something with how EE expects me to access the hook.
I have php enabled on the blog/detail template, I also have it set as input not output.
When I echo the $EXT global in the template, I don’t see that this hook is active.
I know that I am missing most of what needs to happen here. Can anyone enlighten me? I want to call a function upon successful completion of a comment.
If there is an easier approach, please let me know, otherwise I was just going to hack the mod.comment.php to perform as required in this instance.
thanks
Thanks for the move. I guess I have more questions. 1. Is it possible to call this hook from a template, the blog/detail template in particular? How? 2. Do I need to modify the mod.comment.php to edit this hook? I am missing something with how EE expects me to access the hook. I have php enabled on the blog/detail template, I also have it set as input not output. When I echo the $EXT global in the template, I don’t see that this hook is active. I know that I am missing most of what needs to happen here. Can anyone enlighten me? I want to call a function upon successful completion of a comment. If there is an easier approach, please let me know, otherwise I was just going to hack the mod.comment.php to perform as required in this instance. thanks
Hi Fodney:
1: No you can’t call extension hooks from templates. You have to build an actual extension to call an extension hook. 2: No! Definitely don’t go modding any EE files! That leads down an ugly slippery slope because any upgrades will break your site! The extension system is set up to allow you to do the kind of post-processing you’re talking about without having to go modifying EE files themselves.
Have you gone through the extension development tutorial? That would be a great way to learn about how extensions work and help you towards your goal.
Morning fodney- and yep, an extension is definitely the way to go. Let’s see- best thing to do when you’re learning is to copy from a good example- Comment spam prevention at least relates to comments, and Paul wrote it so you know the code base is a good one for inspiration.
I suspect it uses an earlier hook than you need- it gets the post data and does some checks on whether the comment should be allowed. You need to snag in a bit later than that- AFTER the comment has been successfully entered.
So- insert_comment_end looks like a good option. Everything is done by that point and if they got that far, a comment was added.
So- take a look at the spam prevention extension for some ideas, and the extension development docs for some more ideas.
This is a good one to start with- it really should be fairly simple. (And once you do this one- could write one to handle the same thing for entry posting.)
That help?
Hi Fodney: 1: No you can’t call extension hooks from templates. You have to build an actual extension to call an extension hook. 2: No! Definitely don’t go modding any EE files! That leads down an ugly slippery slope because any upgrades will break your site! The extension system is set up to allow you to do the kind of post-processing you’re talking about without having to go modifying EE files themselves. Have you gone through the extension development tutorial? That would be a great way to learn about how extensions work and help you towards your goal.
Yeah, I went through the tutorial, but I have so little experience with EE conventions it was just easier to modify the two files needed. Thanks for the reply, and I completely understand the warnings and agree, writing an extension, or two in this case, would be the best solution, unfortunately the budget doesn’t allow for the added complexity.
My mod is super simple and easy, that I will be able to move it forward upon upgrades to the comments mod or the forums core. It seemed to be the less complex solution, adding 2 lines of code to each file (the include and the function call), in the specific hook sections, was quick, simple and painless.
thanks
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.