Please or Register to create posts and topics.

Making Custom fields Required

Hi @asgaros,

Thanks again for the plugin and all the support. I’ve set up a custom dropdown field in the editor, and would like to make it required. I’m assuming that I’d have to somehow check for value and then cancel the submission while displaying the notice. Would I use the after add topic submit hook?

Thanks!

Never mind! I figured it out! For those with the same question, here’s what I used:

function require_post_type($status) {
    global $asgarosforum;
    if (empty($_POST['post-tag'])) {
        $asgarosforum->add_notice(__('You must select post type.', 'asgaros-forum'));
        return false;
    } else {
        return true;
    }
    return $status;
}
add_filter('asgarosforum_filter_insert_custom_validation', 'require_post_type');

 

Asgaros has reacted to this post.
Asgaros

Hello @jackfukushima

I am happy to hear that you already found the correct filter to add your custom validation-rules to the forum. If you have further questions, please let me know.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hi @asgaros

Yes, thank you! I actually do have one more question about showing the custom field only in creating a new topic and not showing it in the editor for creating a new reply. Is there a way to check for which editor is being shown?

Thanks!

Hello @jackfukushima

I assume that you use theĀ asgarosforum_editor_custom_content_bottom action to add the custom field to the editor. Its first parameter contains the editor-view which you can use, for example:

function my_custom_field($view) {
  if ($view === 'addtopic') {
    //
  } else if ($view === 'addpost') {
    //
  } else if ($view === 'editpost') {
    //
  }
}
add_action('asgarosforum_editor_custom_content_bottom', 'my_custom_field', 10, 1);

 

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Thanks so much! Your support is amazing!

Asgaros has reacted to this post.
Asgaros