Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.0k views
in Q2A Core by
In my q2a website everyone can ask even if they are not registered users.

But most people don't write their name when they ask a question. Because it is optional and as you know if something is optional people become lazy to do it.

So help me make it mandatory
Q2A version: 1.8.3

1 Answer

+5 votes
by
selected by
 
Best answer

One way to accomplish it is creating a plug-in that:

  1. Makes it mandatory
  2. Removes '(optional)' from the field label
  3. Shows an error message when appropriate

A filter module can be added to make it mandatory. Something like:

public function filter_question(&$question, &$errors, $oldquestion)
{
    $userid = qa_get_logged_in_userid();

    if (!isset($userid) && qa_opt('allow_anonymous_naming') && array_key_exists('name',$question) && empty($question['name']))
        $errors['name'] = 'Please provide more information';
}

You might also include a custom language phrase here, rather than hard-coding it.

In addition, you can override qa-include/pages/ask.php and qa-include/pages/question.php such that the language phrase gets updated and the error message gets added (if any) after ask.php:297 (when creating questions) and question.php:241 (when editing questions). You can check qa_set_up_name_field() to know what the form looks like.

I hope this information is helpful.

by
+1
thank you, very much
by
+1
You're welcome!
...