Contact Form 7 – Replace database configured form template with a static file

I answered this question on Stackoverflow, and reposting the answer here.

We would never edit it there though, it’d be impossible,

quite, the CF7 plugin was never conceived for anything more complex than a contact form unfortunately. You may want to play around with the Smart Grid-layout extension which was specifically designed for creating and maintaining complex forms. It has a modular functionality that allows you to build a form using sub-forms, making form maintenance much easier.

It also uses the excellent CodeMirror editor as its code editor, much more powerful than the ridiculous textarea used in CF7 plugin.

simply have CF7 use markup from this file directly?

yes, that the simplest way to solve your problem. Hook the following CF7 filter,

add_filter('wpcf7_default_template', 'load_custom_form_template',10,2);
function load_custom_form_template($template, $prop){
    if($prop !== 'form') return $template;
    include( 'path-to-your-default-form.php');
    return $template;
}

Now, if you do use the Smart Grid extension which has the ability to load form specific js and css scripts (only on the pages where the form is loaded), then you can hook the following actions to add JavaScript template,

add_action('cf7sg_default_custom_js_template', 'use_js_script',10,1);
function use_js_script($cf7_key){
  include_once 'path-to-your-default-js';
}

and CSS stylesheet template,

add_action('cf7sg_default_custom_css_template', 'use_css_script',10,1);
function use_css_script($cf7_key){
  include_once 'path-to-your-default-css';
}