Daniel Weller
asked 5 years ago

Will you ever allow the option of customizing many of the plugin features? Some of the things may be:

  • disabling the automatic email sent upon submitting a new question
  • customizing the submit a question form (including required fields)
  • the option to have similar functionality like dwqa but for statements instead of questions

I am using it in a really hacky way currently and that is where my questions come from… I am passing in a value for the email automatically every time a new question is submitted and hiding the field so that the user does not see it. 

4 Answers
DominicStaff
answered 5 years ago

Hi,
1. Disabling the automatic email sent upon submitting a new question.
– To resolve this issue, you can setting in the Dashboard > Q&A > Settings > Notification.
2. Customizing the submit a question form (including required fields).
– You can open the dwqa-submit-question.js file in the folder path “yourdomain\wp-content\plugins\dw-question-answer\inc\templates\default\assets\js\dwqa-submit-question.js”. Then do as the following:

Step 1 : Comment the following line code
– Find the line 142->145 :

 if (!$('#question-tag').val()) {
                $('#question-tag').val($('#question-tag').attr('placeholder'));
            }
            console.log('test');

Step 2 : Add some code to validate require fields.
– Find the line 89:
var email_field = t.find(‘[name=”user-email”]’);

– Add the following code under line 89.

if( $('#question-category').find(":selected").val() == -1 ) {
            $('#question-category').addClass('required');
            returnDefault($('#question-category'));
            flag = false;
        }
        if( $('#question-tag').val().length == 0 ) {
            $('#question-tag').addClass('required').attr('placeholder', 'Please enter your question tag');
            flag = false;
        }

        tinyMCE.triggerSave();

        if( $('#dwqa-question-content-editor').val().length == 0 ) {
            $('.content-required').remove();
            $('.input-content').append('<span class="content-required" style="color:#e8b3b3">*Please enter question content.</span>');
        }

3. The option to have similar functionality like dwqa but for statements instead of questions
– At the moment, our plugin does not support this issue.

Hope this helps !
 

Daniel Weller
replied 5 years ago

Thank you it does help some. For number 1. – I will visit Dashboard > Q&A > Settings > Notification but do not see an option to disable emails… Should I erase the email template to disable emails?For number 2. -I should have specified more clearly because I wanted to not require fields. Could you provide an example of that? For number 3- thank you

Daniel Weller
answered 5 years ago

I thought I would share my solution of how to remove the title from the submit a question form since you gave an example of how to require a question field. I assume you can do something similar for another field, should you need to remove something else instead.
To remove the title form validation for submitting a question, go to file 

dw-question-answer/inc/templates/default/assets/js/dwqa-submit-question.js

and go to line 78 and comment out or remove lines 78-88. 

/*if ($('#question-title').val().length <= 3 || $('#question-title').val() == $('#question-title').attr('placeholder')) {
e.preventDefault();
var placeholder = $('#question-title').attr('placeholder');
if ($('#question-title').val().length == 0) {
$('#question-title').addClass('required').attr('placeholder', dwqa.error_missing_question_content);
} else {
$('#question-title').addClass('required').after('* ' + dwqa.error_question_length + '');
}
returnDefault($('#question-title'), placeholder);
flag = false;
}*/

You also need to comment out another required validation file at 

dw-question-answer/inc/actions.php

go to line 291 and comment out lines 291-295.

/*if ( empty( $_POST['question-title'] ) ) {

$dwqa_submit_question_errors->add( 'submit_question', 'You must enter a valid question title' );
return false;
}*/

The above code should be enough to allow you to have an optional title. If you wish to completely remove the title input, you need to remove another portion of the plugin and make sure that every occurrence of  

get_the_title();

is changed to something. I used

get_the_content();

 to display the content in places where the title was expected to go. 
To completely remove the title from the form, go to file -> 

dw-question-answer/inc/templates/default/question-submit-form.php

go to around line 42 and remove these lines:

<div class="input-title">
<label for="question-title"><?php _e( 'Your question', 'dwqa' ) ?> *</label>
<input type="text" name="question-title" id="question-title" placeholder="<?php _e( 'How to...', 'dwqa' ) ?>" autocomplete="off" data-nonce="<?php echo wp_create_nonce( '_dwqa_filter_nonce' ) ?>" value="<?php echo isset( $_POST['question-title'] ) ? esc_html( $_POST['question-title'] ) : ''; ?>" />
<span class="dwqa-search-loading dwqa-hide"></span>
<span class="dwqa-search-clear fa fa-times dwqa-hide"></span>
</div>

 
 

DominicStaff
answered 5 years ago

Ohm Daniel Weller, very supprised, I really vote five stars for your solution, my buddy 🙂
I see that you are very comfortable to coding. Hope that you can join our community to share your experience as well as to connect the community. 
Hope that you have a merry Christmas <3
 

bryan alman
answered 4 years ago

What if I will require my users to add question details? how should I do that?

nobita
replied 4 years ago

hi bryan , what details you need ? I can tell you this: the action when an user ask a question lie in dw-question-answer\inc\action.php, function dwqa_submit_question() about line 280.
When you ask a question , it’s a submit form so it use$_POST to send data from the input. So it’ll be like :

if (  ! isset(  $_POST['question_detail'] ) ) {
  //Coding here to request user to add detail...
}

Like if you want the user add the category then it should be like this :

if (  isset(  $_POST['question-category'] ) && ""  !=  $_POST['question-category']  ) {
  //Coding here to add question 
} else {
  echo "you need to select category",
}
nobita
replied 4 years ago

for the details sections : You can see a line code about line 310:
$content = isset( $_POST['question-content'] ) ? dwqa_pre_content_filter( wp_kses( $_POST['question-content'] , $post_submit_filter ) ) : '';

below that line : add these

if ( empty( $_POST['question-content'] ) ) {
        $err_message = __( 'You need to enter question details.','dwqa' ).'
'; $dwqa_current_error = new WP_Error( 'submit_question', $err_message ); return false; }
postik
replied 4 years ago

@nobita, Thank you so much you solve my problem! Regards,

Powered by DW Question & Answer Pro