Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
864 views
in Plugins by
I have succeeded in adding some extra custom fields to the edit question form via a plugin layer.

However, when you save the question after editing it, the code in the core (qa-page-question-post.php on lines 119 - 122) runs qa_page_q_edit_q_submit() and then immediately redirects to the question with qa_redirect().  The redirect makes it impossible to save my new extra fields information to the database.

I have commented out the qa_redirect() in the core and added a if (qa_is_http_post()) to my layer and then new information is saved without a problem.

However, I do not want to change the core. How can I ensure that the new fields are processed correctly without changing the core when I submit the form? What can I add to my layer to have the new fields I have added get processed before there is a redirect?
Q2A version: 1.5
by
edited by
By the way the qa-page-question-post.php is called on the qa-page-question.php line 157-159 as follows:     if (qa_is_http_post() || strlen($pagestate)) require QA_INCLUDE_DIR.'qa-page-question-post.php';

So basically whenever you edit a question, qa-page-question-post.php is automatically fired, and then the page redirects, as per above, so I can't add any custom processing to the edit question form, unless you get rid of the redirect somehow by editing the core. There must be some way in the layer to "intercept" this, I suppose

1 Answer

+1 vote
by
I am not sure if I solved this correctly, but what I decided to do is to create an event plugin and in the process_event function I did a if ($event == 'q_edit') { } - and in that if clause I added my code to update the database with my custom data. Surprisingly it worked. Wondering if this is the correct way to approach this, i.e. Event module.
by
Yes, this sounds like a very good solution, since there's not quite an officlal way yet to add fields to question asking/editing forms.
by
This is how I would do it too - all the $_POST variables are retained during the event reporting routine, I think, so it works.
by
Yes, I was pleasantly surprised that all the $_POST variables were retained. Makes the event module quite powerful for other potential applications.
by
Could somebody PLEASE put this together and add an Extra-Fields-Plugin ?
...