• Resolved pixelaar

    (@pixelaar)


    Hi,
    I had created a multiple image upload metabox with my custom post type. I had applied it to my post type and everything is working nice. but I have a front-end submission form where I am trying to show image upload option but there always showing error “Metabox configuration is required to have an ID parameter.”. Can anyone please advice ? I am sharing my full code.

    
    add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
    /**
     * Define the metabox and field configurations.
     */
    function cmb2_sample_metaboxes() {
    
        // Start with an underscore to hide fields from custom fields list
        $prefix = '_pxlr_';
    
        /**
         * Initiate the metabox
         */
        $cmb = new_cmb2_box( array(
            'id'            => 'pxlr-ticket-attachment',
            'title'         => __( 'Ticket Attchments', 'cmb2' ),
            'object_types'  => array( 'ticket', ), // Post type
            'context'       => 'normal',
            'priority'      => 'high',
            'show_names'    => true, // Show field names on the left
            // 'cmb_styles' => false, // false to disable the CMB stylesheet
            // 'closed'     => true, // Keep the metabox closed by default
        ) );
    
        $cmb->add_field( array(
            'name' => 'Add Attchments',
            'desc' => 'Please attch your problem screenshot',
            'id'   => $prefix . 'ticket-attachment-list',
            'type' => 'file_list',
            // 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
            // Optional, override default text strings
            'text' => array(
                'add_upload_files_text' => 'Add or Upload Files', // default: "Add or Upload Files"
                'remove_image_text' => 'Remove Image', // default: "Remove Image"
                'file_text' => 'File', // default: "File:"
                'file_download_text' => 'Download', // default: "Download"
                'remove_text' => 'Remove', // default: "Remove"
            ),
        ) );
    
        // Add other metaboxes as needed
    
    }
    

    Created Shortcode with the following code

    add_shortcode( 'pxlr-ticket-metabox-shortcode', 'pxlr_do_frontend_show_custom_metabox' );
    /**
     * Shortcode to display a CMB2 form for a post ID.
     * @param  array  $atts Shortcode attributes
     * @return string       Form HTML markup
     */
    
    function pxlr_do_frontend_show_custom_metabox( $atts = array() ) {
    
        global $post;
    
        /**
         * Depending on your setup, check if the user has permissions to edit_posts
         */
        if ( ! current_user_can( 'edit_posts' ) ) {
            return __( 'You do not have permissions to edit this post.', 'lang_domain' );
        }
    
        /**
         * Make sure a WordPress post ID is set.
         * We'll default to the current post/page
         */
    
        if ( ! isset( $atts['post_id'] ) ) {
            $atts['post_id'] = $post->ID;
        }
    
        // If no metabox id is set, yell about it
        if ( empty( $atts['id'] ) ) {
            return __( "Please add an 'id' attribute to specify the CMB2 form to display.", 'lang_domain' );
        }
    
        $metabox_id = esc_attr( $atts['id'] );
       // $object_id = absint( $atts['post_id'] );
        // Get our form
        $form = cmb2_get_metabox_form( $metabox_id );
    
        return $form;
    }

    And in my post type submission template I had applied this

    <?php echo do_shortcode('[pxlr-ticket-metabox-shortcode id="pxlr-ticket-attachment"]')?>
    

    Always showing same error. So I am confused. Is there anything I missed ?

    Also for post submission front-end form is there anything I have to follow ?

    Thanks in Advance for your valuable time and great support.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter pixelaar

    (@pixelaar)

    I also tried with
    <?php echo jt_cmb2_do_frontend_form_shortcode( array( 'id' => 'pxlr-ticket-attachment' ) ); ?>

    But no luck. Still having the error.

    Also I tried to change the ID name by inspecting from backend field but no luck. Any advice ?

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Hello, please review the details on the wiki for using CMB2 on the frontend: https://github.com/WebDevStudios/CMB2/wiki/Bringing-Metaboxes-to-the-Front-End

    The notable part being that the cmb2_admin_init hook should be used only to register cmb2 fields that you want to only show in the admin.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If the change Justin suggested doesn’t take care of it, and you’ve reviewed the wiki page, let us know and we’ll try figuring it out from there.

    Thread Starter pixelaar

    (@pixelaar)

    Its now loading in my frontend by applying cmb2_init . I was trying by cmb2_admin_init instead of cmb2_init so it was generating error. Now my meta box is showing in frontend submission. But there I am handling my own form submission and all were working fine. But after your field appear its not creating new post and there after meta box its showing another save button. How to remove that save button and store and save file and create new post with my own submission button as before ? Is there it will save data automatically or I have to add something in my form handler function ?

    Thanks in advance for your valuable time.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What code are you using to handle the form submission?

    This would also be a good thing to look over in case you hadn’t already: https://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/

    Thread Starter pixelaar

    (@pixelaar)

    I already read the article. I just want to remove your save button as I have my own and when submit is that save the data automatically like to save Category I am doing $category = array( absint( sanitize_text_field( $_POST[ 'Pxlr_ticket_category' ] ) ) ); at my form submission time. I already have my own form with submit button so how I can remove save button ?

    When my form submit the uploaded media file will be save automatically. Any advice ?

    Also after adding media button my form submission not creating post. After submitting form its reloading same page with no error. But before adding media field all was ok and working perfect.

    Thanks

    Thanks in advance.

    • This reply was modified 7 years, 9 months ago by pixelaar.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Seeing the code you’re utilizing for the saving/processing would still be appreciated, it’ll give a better idea of exactly what’s going on, and I could also recreate on my own to see if I’m finding anything glaringly obvious.

    For what it’s worth at the moment, I’ve never personally known of any way to not have the built-in submit button not show with the frontend display. Personally I’m curious if all of it can be adapted to handle the way you’re wanting, without trying to override so much.

    Thread Starter pixelaar

    (@pixelaar)

    Actually I am working with a custom post type where user will submit their problem from a frontend form and my staff will reply its like small support system. So when user submit their problem its very important to submit images of the problem so I think I need to add option so user can attch file and then can submit. Check my attached image. I created a form with subject and message field with a submit button and when user submit the form I am creating custom post inside. So I already applied the submission handelar and tested all works very fine. Now I want to add image attachment option and hanging with that as I got one save and another submit button created by me.

    I am new with CMB2 so asking too many Question , I am very sorry for that , I know you are really working hard to make it really nice and I like your system very much but I need time to make myself used to with it.

    Thanks in advance for your valuable time.

    Frontend Submission Form

    Check image from this link if attachment not working https://prnt.sc/e8t8ye

    • This reply was modified 7 years, 9 months ago by pixelaar.
    • This reply was modified 7 years, 9 months ago by pixelaar.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I know CMB2 has file upload fields available, which may be of use to you. If I recall right, it’ll upload as media into the media library, and then save information about the images to post meta, including attachment ID and a URL for the image itself.

    The post type you’re creating with the form submission isn’t too important really, in terms of debugging/altering behavior.

    I still believe you can handle all of this with CMB2 alone, and not worrying about your own submit button etc to handle part of it. Just a matter of what you’re doing when, what content is available at that point, and how you’re handling what is available.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Shortcode Not Showing in Front-end Post Submission’ is closed to new replies.