I have a custom wordpress fonts-picker customizer control that allows a user to select their desired fonts on their site. The HTML bit of the control is rendered via the content_template method of the WP_Customize_Control class as below:
public function content_template() {
?>
<div class="font-picker-wrapper">
<div class="fonts-picker-header">
<# if ( data.label ) { #>
<span class="customize-control-title">
{{ data.label }}
</span>
<# } #>
<# if ( data.description ) { #>
<span class="description customize-control-description">
{{ data.description }}
</span>
<# } #>
</div>
<div class="font-picker-body">
<form role="form" name="font-picker-form" class="ivio-font-picker">
<label for="{{data.id}}-font-family-select" class="description customize-control-description">
<?php echo esc_html(__("Font Family", "ivio")); ?>
</label>
<select name="{{data.id}}-select" id="{{data.id}}">
<# if ( data && data.systemFonts ) { #>
<optgroup id="ivio-system-fonts" label="System Fonts">
<# _.each(data.systemFonts, function(font, key) { #>
<option value="{{font.family}}" <# (data.value && (data.value.fontFamily===font.family))? print("selected") : print("") #>>
{{ font.family }}
</option>
<# }) #>
</optgroup>
<# } #>
<# if (data && data.googleFonts ) { #>
<optgroup id="ivio-google-fonts" label="Google Fonts">
<# _.each(data.googleFonts, function(font, key) { #>
<option value="{{font.family}}" <# (data.value && (data.value.fontFamily === font.family))? print("selected") : print("") #> >
{{ font.family }}
</option>
<# }) #>
</optgroup>
<# } #>
</select>
<div class="selected-font-variants">
</div>
<div class="selected-font-subsets tag-cloud">
</div>
</form>
</div>
</div>
<?php
}
The problem is when the above HTML markup is rendered on the customizer frontend, the opening and closing form HTML tags do not get rendered yet the children they contain get rendered. I need the form tags to be rendered as the form is submitted via JavaScript where the form is converted to json using the form.serializeArray() javascript function. Any help will be much appreciated. I’ve been stuck here for quite a while now.