JS call mb_frontend_form shortcode

Support MB Frontend Submission JS call mb_frontend_form shortcodeResolved

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

    Hi

    I want to load the mb_frontend_form using the fetch API. I can call the form successfully but the form does not include the necessary JS/CSS files. So just the form html loads. Any ideas why? or even if its is possible?

    example.php

    
    define( 'WP_USE_THEMES', false );
    require_once( '../../../../../../wp-load.php' );
    echo do_shortcode('[mb_frontend_form id="dc-product" submit_button="Update" ajax="true"]');
    

    then in my themes js file...

    
    <script>
        let container = document.getElementById('content');
        
        const testform = async () => 
        {
            const url = 'http://192.168.0.14/freestuffgroup/wp-content/plugins/drip-create-plugin/includes/functions/custom-scripts/metabox-form-query.php?rwmb_frontend_field_post_id=339';
            
            fetch(url,{
                method: 'GET'
            })
            .then(response => {
                if (response.ok) {
                    return response.text();
                } 
            })
            .then(data => { 
                    container.innerHTML += data; 
                }
            })
        };
        
        testform();
    </script>
    
    #34224
    Long NguyenLong Nguyen
    Moderator

    Hi Nick,

    I've researched around this case and realize that it's not possible to load JS, CSS files via Ajax or fetch API. In this case, you can pass the post ID to the URL and redirect the user to a new page to edit the post (like your idea).

    Refer to this documentation https://docs.metabox.io/extensions/mb-frontend-submission/#dynamic-population

    #34239
    Nicholas CoxNicholas Cox
    Participant

    Hi Long,

    Ok thanks for taking a look, it is a shame it cannot be done as it would have been cool. I will try the other idea instead.

    Thanks

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