Forum Replies Created
-
AuthorPosts
-
KopDoc
ParticipantHi Long,
I got no error message in the debug log, and no more clue with the console tab.
But I identified where my problem is located : in inc/validation.php
If I add in the public function enqueue() these lines :
if ( empty( $object->meta_box['validation'] ) ) { return; }My form is validated and works as intended. Is that something that could be taken into account for the next updates ?
October 23, 2020 at 5:59 AM in reply to: ✅Form verification - required fields stopped working #22541KopDoc
ParticipantHi,
I had a look but changing my own form for Meta Box's would really be too long, and will not let me do all I'm doing through wordpress' function add_metabox.
But I found out more precisely the source of the problem : it was not MB Relationship, but Meta Box plugin, when it updated from version 5.2.10 to 5.3 !
I guess this is not your field of action anymore, so I'll ask in the right section.
Thanks for your help, you can mark this topic as closed 🙂
October 19, 2020 at 10:13 PM in reply to: ✅Form verification - required fields stopped working #22465KopDoc
ParticipantWell, that's a lot of work because my form is long, has multiple javascript functions to change dynamically which fields appear and which are required, and the data is stored in a custom table.
It used to work with MB Relationship, so I don't know if the issue comes from my code or MB relationship's update, but I think there might be a simpler solution.
I will try to recreate my form with Meta Box's filter and will come back to let you know the results. If you have another idea in between, do not hesitate cause it could save me a lot of time 🙂
Have a good day !
October 19, 2020 at 1:22 PM in reply to: ✅Form verification - required fields stopped working #22455KopDoc
ParticipantHi Long, thank you for your fast answer
I've tried deactivating all plugins except Metabox, MB Relationship and my own plugin defining the CTP, I also switched from my child theme to the original, with the same result.
If I add your required field lines to one of the MB relationship metaboxes, as expected, the relationship actually is required and the post cannot be saved. But no difference with my form.
The code is as follows in my plugin :
// CPT CREATION add_action( 'init', 'ht_custom_post_lien_externe' ); function ht_custom_post_lien_externe() { $labels = array( 'name' => _x( 'Liens Externes', 'post type general name' ), 'singular_name' => _x( 'Lien Externe', 'post type singular name' ), ); $args = array( 'labels' => $labels, 'description' => 'Articles, references et sites webs', 'public' => true, 'exclude_from_search' => false, 'menu_position' => 5, 'supports' => array( 'title', 'author' ), ); register_post_type( 'liens_ext', $args ); } // TAXONOMy FOR THE CPT add_action( 'init', 'create_cat_taxonomies' ); function create_cat_taxonomies() { $labels = array( 'name' => _x( 'Catégorie', 'taxonomy general name', 'textdomain' ), 'singular_name' => _x( 'Catégorie', 'taxonomy singular name', 'textdomain' ), 'search_items' => __( 'Chercher une catégorie', 'textdomain' ), 'all_items' => __( 'Toutes les catégories', 'textdomain' ), 'parent_item' => __( 'Catégorie parente', 'textdomain' ), 'parent_item_colon' => __( 'Catégorie parente:', 'textdomain' ), 'edit_item' => __( 'Modifier catégorie', 'textdomain' ), 'update_item' => __( 'Mettre a jour la catégorie', 'textdomain' ), 'add_new_item' => __( 'Ajouter une catégorie', 'textdomain' ), 'new_item_name' => __( 'Nouveau nom de catégorie', 'textdomain' ), 'menu_name' => __( 'Catégories', 'textdomain' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'categorie' ), ); register_taxonomy( 'categorie', array( 'liens_ext' ), $args ); } // ADD METABOXES MB RELATIONSHIP add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( [ 'id' => 'link_to_post', // Vers les articles 'from' => [ 'object_type' => 'post', 'post_type' => 'liens_ext', 'admin_column' => true, 'meta_box' => [ 'title' => 'Liaison article(s)', ], ], 'to' => [ 'object_type' => 'post', 'admin_column' => true, 'meta_box' => [ 'title' => 'Lien(s) associé(s)', ], ], ] ); } ); add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( [ 'id' => 'link_to_category', // Vers les catégories 'from' => [ 'object_type' => 'post', 'post_type' => 'liens_ext', 'admin_column' => true, 'meta_box' => [ 'title' => 'Liaison catégorie(s)', ], ], 'to' => [ 'object_type' => 'term', 'taxonomy' => 'category', ], ] ); } ); add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( [ 'id' => 'link_to_tags', // Vers les étiquettes 'from' => [ 'object_type' => 'post', 'post_type' => 'liens_ext', 'admin_column' => true, 'meta_box' => [ 'title' => 'Liaison étiquette(s)', ], ], 'to' => [ 'object_type' => 'term', 'taxonomy' => 'post_tag', ], ] ); } ); /* REGISTER FORM METABOX */ function hcf_register_meta_boxes2() { add_meta_box( 'formulaire_liens', // ID attribute of metabox __( 'Formulaire', 'hcf' ), // Title of metabox visible to user 'formulaire_liens', // Function that prints box in wp-admin 'liens_ext', // Show box for posts, pages, custom, etc. 'normal', 'high' ); } add_action( 'add_meta_boxes', 'hcf_register_meta_boxes2' ); /* LOAD FORM FROM SEPARATE FILE */ function formulaire_liens( $link ) { include plugin_dir_path( __FILE__ ) . './form_links.php'; } /* SAVING POST DATA */ function save_meta_box_liens_ext( $post_id ) { if ( get_post_type( get_the_ID() ) == 'liens_ext' ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( $parent_id = wp_is_post_revision( $post_id ) ) $post_id = $parent_id; // Enregistrement des données du formulaire // Stuff to save form data.... } add_action( 'save_post', 'save_meta_box_liens_ext' ); -
AuthorPosts