Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.8k views
in Q2A Core by

I would like to provide (in some cases) an initial question template which is shown in the editor (instead of an empty text area) when a user asks a question. Preferrably, I'd like to provide this text via the URL, something like:

http://www.question2answer.org/qa/ask?template=*someText*

 Is there any way to do this?

Q2A version: 1.6.3

2 Answers

+1 vote
by
selected by
 
Best answer

I wouldn't hack the core either. The thing is creating a plugin or modifying the qa-theme.php file... don't seem to be choices either, unless you want to parse HTML :/ I hope you really don't.

Anyway, you can still avoid hacking the core and parsing HTML by modifying the Q2A CKEditor plugin itself, which is the one responsible for setting that value. Check this line:

https://github.com/q2a/question2answer/blob/v1.6.3/qa-plugin/wysiwyg-editor/qa-wysiwyg-editor.php#L161

Exactly there add this code:

if (qa_request() === 'ask' && $fieldname === 'content' && !qa_is_http_post() && empty($content)) {
    $content = qa_get('template');
}

by
This works, thanks! And it actually works even better than @Ami's version (there, some characters have not been transmitted correctly, for example ">" was displayed as ">" (or so - I mean the html code)). This way is better with regard to upgrades, too - but what happens if the editor plugin is upgraded?
by
You'll have to apply this patch again. Anyway, you can't get away without doing so because, as I mentioned above, it is the editor plugin itself what you want to change. If you want to have a longer term solution, you could probably clone the plugin apply this patch and use that custom plugin instead of the default one. But again, it is your call... of course, the safest thing to do will always be not to change anything and use the code core/plugin code as it is :)
by
Yeah, ok. I got it :-)
+1 vote
by

Try this out here . This should work  ( Though I did not tested this . Hope this will work )

At https://github.com/q2a/question2answer/blob/master/qa-include/pages/ask.php#L157 insert below code .

if ( !qa_clicked( 'doask' ) && empty( $in['content'] ) ){
    $in['content'] = qa_html( qa_get( 'template' ) );
}

by
Oopss . Sorry guys , I missed the openning brace . Thank you @Scott for pointing this out . I have updated the answer . Thanks :)
by
Thanks for the addition!
by
@Scott: Just since you mentioned it - is there a good tutorial on how to make plugins? You're certainly right that changing the core is not a long-term solution...
...