Skip to content

Instantly share code, notes, and snippets.

@rmpel
Created March 11, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmpel/0c74d3dcb5bc83cc0afafe68b7717db0 to your computer and use it in GitHub Desktop.
Save rmpel/0c74d3dcb5bc83cc0afafe68b7717db0 to your computer and use it in GitHub Desktop.
Auto-balance HTML for ContactForm 7
<?php
/**
* WHY? Because invalid HTML will break a page, will break visible form feedback.
* Still, WHY? Well, you are right, CF7 should do this all on their own.
*/
add_action( 'wpcf7_save_contact_form', function(WPCF7_ContactForm $contact_form) {
// this is an action, contact_form not given as pointer, so get the pointer from CF7;
$cf = WPCF7_ContactForm::get_current();
// get the properties, we need to change the form
$props = $cf->get_properties();
// auto-balance HTML for the form data
$props['form'] = force_balance_tags( $props['form'] );
// save the new properties
$cf->set_properties($props);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment