[Forminator Pro] Clone/Copy Form

Hi there,
i wanted to ask, if it's possible to clone a Forminator Form via the really great API including all fields and settings, so a news form is written to the db?
https://premium.wpmudev.org/docs/wpmu-dev-plugins/forminator-api-docs/

Best regards,
Andreas

  • Andreas
    • WPMU DEV Initiate

    Hi there,
    i want to clone/copy a form via code. I'm writing a plugin. And in there, users can copy/clone forms, they already filled out, so that they don't have to type everything again.

    Alternatively it could be an even easier method to take a "base forminator form" and prefill it with the data of another, already saved form.

    Is there a way to achieve any of the above via the API.

    Best regards,
    Andreas

  • Predrag Dubajic
    • Support

    Hi Andreas,

    I'm not sure if this can be done via API but I'll forward this over to our devs so they can check it out and see if it's possible via API or if you would need to copy the existing functionality to clone forms.
    We're also working on releasing an article on Forminator API docs so that might help as well once it's out :slight_smile:

    Best regards,
    Predrag

  • Andreas
    • WPMU DEV Initiate

    hi there,
    awesome and thanks!

    as i said: i think the easier solution would be if i'd know how to prepoulate form field in an existing form which i get via get_form($id) and display it with these prefilled values.
    maybe the devs have an easy solution for this :slight_smile:

    best regards!

  • Predrag Dubajic
    • Support

    Hi Andreas,

    It should be possible to do this with get_form to retrieve the form and then use add_form to add new form, here's an example:

    // Form ID
    $form_id = 290;
    
    // Get form object
    $form = Forminator_API::get_form( $form_id );
    
    // Get form fields grouped
    $wrappers = $form->get_fields_grouped();
    
    // Get form settings
    $settings = $form->settings;
    
    // Unset the form ID
    unset( $settings['form_id'] );
    
    // Add form
    Forminator_API::add_form(
        $form->name,
        $wrappers,
        $settings
    );

    Hope that helps :slight_smile:

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.