update post_id inside the DOM after the shortcode has rendered

Support MB Frontend Submission update post_id inside the DOM after the shortcode has renderedResolved

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

    Hi

    I have the following shortcode
    [mb_frontend_form id="dc-product-test" post_id="1" submit_button="Submit" ajax="true"]

    I was wondering is it possible to update the post_id of the rendered form to "0" or something else if a user clicks on a button inside the DOM.

    I am assuming there is not a clean way to do this. I want to do this so i can change the post_id to be "0". So if a user clicks on a 'duplicate' button it will create a new post with the same data rather than updating the existing post. it was just a quick way for users to duplicate listings on my website if they are on a post edit screen page.

    thanks

    #36659
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The attribute post_id and other attributes of the form (form settings) are saved to the database in the table wp_options with the key mbfs_key. Each form has its own key based on the form settings.
    So it is possible to create a new form and set the post_id to 0 and generate a new key to create a new post after submitting but you will need a lot of custom code to do that.

    Instead of modifying the post_id attribute of the form, you can try to use the action hook rwmb_frontend_before_save_post and set the post_id to 0 to duplicate a post. For example:

    add_action( 'rwmb_frontend_before_save_post', function( $object ) {
        $object->post_id = 0;
    } );
    #38238
    Nicholas CoxNicholas Cox
    Participant

    ok thanks, ill give that a go

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