Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
910 views
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
by

Jquery my friend :)

Example:

    // 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) {
                e.preventDefault(); 
// prevent submit
                $("#tags").focus();
                $("#tags").css("background-color","#FFFFAA");
                alert("You need to give us at least 2 tags for your question.");
                return false;
            }

            return true;
        });


Hope that helps :)

by
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?
by
You could use AJAX with jQuery to call the script on your site.
by
@Scott,
Thanks, I will try to use jQuery I think. That may be easiest way.
+1 vote
by
You can create a filter module that does your requirements before it gets submitted to the database.

http://question2answer.org/modules.php?module=filter
by
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..
by
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.
...