I already create my own comment form. The next step ist to create the code which validates the form.
The problem i have is to find, what happens if the submit button was pressed. I found out, that the validation is handled in the content.cfc. I learned, that the event cbui_preCommentPost will be used to place any messages, but i can’t find the “route” from pressing the submit button to the function validateCommentPost. This route i need to change to my own validation.
Nearly everything you could do like this is already in the current templates, apart from the ajax ones, the others will have this in there if you wish to browse the default layouts.
After doing other stuff in ContentBox, i have to come back to this issue. First of all, i made a really nice experience with the plugin MessageBox, by extending it with my include to have my own formatting. Very cool stuff and easy to do
So, i’m trying to learn, how i can replace ContentBox internal code with my own. In this case i need to replace the private function validateCommentPost() completely, which is in the handler content.cfc
First, i had the idea to create my own event to replace commentpost and do my own thing. So far so good, but this would start a kind of a bomb, while blog.cfc and page.cfc are having a function commentpost. So, bad idea.
What would be the perfect way to accomplish this? Best practice?
This should get you going in the right direction, feel free to ask any questions. But I don’t understand what your requirements is to remove that and not go with an interception point. If you can provide that maybe we can help more in what you are trying to achieve.
Localising all english strings, e.g. “Please provide a comment!”. i will use i18n for this.
Adding an additional field for answering a simple control question instead of using captcha. The answer needs to be transfered into the function, while the question can change from time to time.
Checking the comment against a JSON-file containing bad spam-words.
And maybe i will use some ideas taken from cfformprotect.
The localisation will be easy as you translate that after it has done what it has done, the additional question can be done with the following blog post.
Checking the comment can be done with an interceptor as well, ContentBox has good support for this already, but you should be able to hook into this with the same interception point. Personally if Luis is reading this, it would be great if there was a pre/post Comment Interception point that would make this even easier.
At least with an interceptor, if you need to turn it off to check that it works in its default configuration, you just turn the interceptor off. I have written a few blog articles about over riding aspects or ColdBox and you can apply that too anything that is done through WireBox.
But yeah, in this case I would not override this function, rather extend its features with interceptors.
If a comment’s content, author ip or email address matches any of these keywords, the comment is automatically moderated. Regular expressions are ok.
If a comment’s content, author ip or email address matches any of these keywords, the comment is automatically rejected with no notifications. Regular expressions are ok.
What version of ContentBox are you on? With a simple interceptor you could load this list dynamically when the app starts up.