• Hello,

    I think it was really useful if one could export and import all settings for a form (fields and html tags, mail settings, messages) via JSON or YAML.

    This way you could a, edit your form in your text editor and outside of WordPress’ backend and b, track your form with version control such as Git.

    Here is how a basic form JSON export might look like using just one text field:
    LINK

    I can help you with that if you want.

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mamibe

    (@mamibe)

    It should be rather easy to implement. I checked the database structure of the forms that Contact Form 7 creates:

    • There is a custom post type wpcf7_contact_form
    • Each form is a post, the post_title
    • In the table wp_postmeta there are some related entries which are all linked to the post_id
    • There are 6 setting entries per form, here are the corresponding meta_keys:
    • _form – here you find the form itself in the same way you edit it in the backend with all [text*] and <p> tags
    • _mail – serialized PHP with all mail settings
    • _mail2 – see above
    • _messages – PHP serialized messages
    • _additional_settings – in cleartext as in the backend
    • _locale – such as de_DE
    • All meta data gets inserted into the posts field post_content, when you update the form, this content updates as well
    • The different setting entries are separated by empty lines and occational 0s in the post_content

    If you would not have the data in both the wp_postmeta and wp_post, all you would have to do to get a JSON/YAML export/import would be to pull that data from the database, transfrom and to the structured text and save it.

    Maybe you can help me understand why the data is saved in both places and which one is the one to change it programmatically.

    EDIT 1:
    The form still works when you delete the data from post_content so maybe it is just a backup!?

    Thread Starter mamibe

    (@mamibe)

    Because Contact Form 7 uses the custom posttype, you can easily export and import all forms with WordPress’ internal tools.

    This will give you a WXR file, which is basically a XML file. You can now convert it to JSON with frankbille’s golang tool go-wxr-to-json-app or convert it online

    A created a sample JSON for your consideration. It can still be tweaked for readibility and external editing, but this is a good start.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Idea: Import and export form settings with JSON/YAML’ is closed to new replies.