Making Custom fields Required
Quote from jackfukushima on June 12, 2019, 11:55 pmHi @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!
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!
Quote from jackfukushima on June 13, 2019, 12:37 amNever 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');
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');
Quote from Asgaros on June 13, 2019, 4:45 pmHello @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.
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.
Quote from jackfukushima on June 13, 2019, 6:05 pmHi @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!
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!
Quote from Asgaros on June 14, 2019, 4:59 amHello @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);
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);
Quote from jackfukushima on June 14, 2019, 7:18 pmThanks so much! Your support is amazing!
Thanks so much! Your support is amazing!