Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Plugins by
retagged by

        function filter_answer(&$answer, &$errors, $question, $oldanswer)
              $errors['content'] = 'this is not allowed';

not working. What am I missing?


From the docs:

As with filter_question(), elements can be added to the $errors array to declare a value invalid.



Q2A version: 1.5.4
I'm not aware of any problem with this. Did you register the filter module in your qa-plugin.php?
yes, I am already using this plugin to filter posted content. Now I added a database query to check if the answer is posted to a closed question, if yes, I assign:  $errors['content'] = 'while writing your answer, this question got closed. Please post to the original question';

Not working. Even not if I want to throw the error directly - i.e. without the if statement or any db query. There is also no error in the logs.
Perhaps another filter module you have installed was written wrong and is clearing the error? Otherwise I'm afraid you'll have to debug it through the core code and see what you find.
This qa_filter_posts() is the only I am using in the entire q2a setup. And I tried only this plugin code without any "extras".

But what I found out:
1. If I use the code above with an answer on an open question it works. Error message appears.
2. If I use the code above with an answer on a closed question, it does not work.

Could it be that the "core code" intercepts the posted answer if question is closed, and just then the "empty" answer arrives at the filter module?
PS: I would not need the filter module if I could change the parentid .... http://www.question2answer.org/qa/26327/
Ah, in qa-ajax-answer.php I see that you check before posting the answer:
if ((@$question['basetype']=='Q') && !isset($question['closedbyid'])) { ... }

I changed it to: if (@$question['basetype']=='Q') { ... }
but still does not work.

edited by
I am more and more certain that this issue should be solved in core.

I think there must be many answers being lost because the question got closed while the user was answering, and then s/he got the message that the answer was closed... and her/his answer was gone.


Can we just add an else to the qa-ajax-answer.php, in the end after:
if ((@$question['basetype']=='Q') && !isset($question['closedbyid'])) { ... }
and throw an error back to the user, so that s/he will see his answer still opened?

Please log in or register to answer this question.