• Register
Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Layer Plugin: Saving Information to Database from Question Edit Form without Changing Core?

0 votes
141 views
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
asked Feb 11, 2012 in Plugins by osseonews
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
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.
answered Feb 11, 2012 by osseonews
Yes, I was pleasantly surprised that all the $_POST variables were retained. Makes the event module quite powerful for other potential applications.
Could somebody PLEASE put this together and add an Extra-Fields-Plugin ?
...