Front End Forms inside Gutenberg Block Render Template

Support MB Blocks Front End Forms inside Gutenberg Block Render TemplateResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38076
    Nicholas CoxNicholas Cox
    Participant

    Hi,

    I want to provide a preview for my custom block and I have realised the front ed forms do not render in the wp admin area. Is there a way to preview the forms in the block editor at all? at the moment by block is just blak as there is nothing to display.

    setup

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
    	$meta_boxes[] = [
    		'title'           => 'Product Filtering Block',
    		'id'              => 'dc-product-filtering-block',
    		'description'     => 'Product filtering form',
    		'type'            => 'block',
    		'icon'            => 'screenoptions',
    		'category'        => 'dc-blocks',
    		'context'         => 'side',
    		'render_template' => __DIR__ . '/template/dc-product-filtering-block-template.php',
    		...

    Inside 'dc-product-filtering-block-template.php' i want to call the following shortcode

    echo $search_title;
    echo do_shortcode('[mb_frontend_form id="dc-product-filtering" post_type="products" confirmation="Updated" submit_button="Update" ajax="true"]');

    The preview of the block does not display the form but it obviously works on the front end when previewing the page.

    Thanks
    Nick

    #38087
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Currently, it is not possible to display a frontend form in the backend, it will lead to some unwanted errors. You can read the details on the file /mb-frontend-submission/src/Shortcode.php

    /*
     * Do not render the shortcode in the admin.
     * Prevent errors with enqueue assets in Gutenberg where requests are made via REST to preload the post content.
     */
    if ( is_admin() ) {
    	return '';
    }
    #38089
    Nicholas CoxNicholas Cox
    Participant

    Hi, ok no problem. I wanted to be able to preview the form in the backend, not load the enqueued scripts. The reason being is that the block just loads a form and a title, without it there is a blank/empty block. I will have to think of a way around it then.

    thanks

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.