Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Q2A Core by
I am looking for any hook or module before post a question. Means when user hit ask a question ( submit ) button and system submit the data to the database I want to do some stuffs before that.

2 Answers

+2 votes

Jquery my friend :)


    // user must give at least 2 tags
    if ($("#tags").length > 0){ 
// checks if we are on page with tag form (ask page!)
        var regForm = $(".qa-form-tall-table").parent();
        regForm.submit(function(e) {
// before submit
            var tagsN = 0;
            // count tags
            var matches = $("#tags").val().match(/\b/g);
            if(matches) { tagsN = matches.length*0.5; }
            if(tagsN<2) {
// prevent submit
                alert("You need to give us at least 2 tags for your question.");
                return false;

            return true;

Hope that helps :)

Great example. Thanks!
In fact I thought about jQuery but than I wan to run third party PHP API before posting question ( goes to database ) for example adding some other form to filled up before they post a question and if they didn't fill than question won't submit to the database... any clue for this?
You could use AJAX with jQuery to call the script on your site.
Thanks, I will try to use jQuery I think. That may be easiest way.
+1 vote
You can create a filter module that does your requirements before it gets submitted to the database.

This may be good way but first time going to deal with filter. Hope it would be a fun.. Thanks.and will get back you guyz if need more help. I may really need you guyz help to make it happen what I am going to do.. will share you as soon as I starts that task..
Is there any way to change form action on Aks a question? I can change in core file but looking for some hook if available.