Using Gravity Forms ‘gform_cdata_open’ PHP filter

The gform_cdata_open filter allows you to wrap the JavaScript output with your form in CDATA blocks to validate your forms with XHTML doctypes.


add_filter('gform_cdata_open', 'my_cdata_open');


  • $cdata_string (string) – Empty by default. Return an opening or closing CDATA block respectively.

More information

See Gravity Forms Docs: gform_cdata_open

Important: Using this function with advanced form JavaScript might cause issues due to how WordPress handles CDATA tags.


Wrapping form JavaScript in CDATA blocks

This example shows how to wrap your form JavaScript in CDATA blocks.

add_filter('gform_cdata_open', 'my_cdata_open');
function my_cdata_open() {
    return '<![CDATA[';

add_filter('gform_cdata_close', 'my_cdata_close');
function my_cdata_close() {
    return ']]>';

Note: As of Gravity Forms 2.5.8, this filter is located in GFCommon::get_inline_script_tag() in common.php.