Keep up to date with Gravity PDF

  • This field is for validation purposes and should be left unchanged.

Jump To Section

Description #description

This filter can be used to change the inner HTML mark-up that’s wrapped around most field – section fields, page fields and the product table are not run through this filter. This mark-up is then sent to the PDF renderer. You can target different field type (like textarea, radio and select) or just modify a single field. Your changes can also be applied to all forms or some.

Just be aware that the CSS Gravity PDF ships in your templates requires this particular format. If you change it you may need to write your own custom CSS to suit.

Parameters #parameters

$html | string
The formatted HTML for the current field
$value | string
The formatted user’s response to the current field
$show_label | boolean
Whether you should show or hide the label
$label | string
The field label currently being processed
$field | array
The Gravity Form field currently being processed
$form | array
The current Gravity Form array
$entry | array
The raw Gravity Form Entry array.
$class | object
The Gravity PDF field wrapper class

Usage #usage

This snippet simplifies the mark-up for most Gravity Form fields (see notes in the description above about unsupported fields):

add_action( 'gfpdf_field_html_value', function( $html, $value, $show_label, $label, $field, $form, $entry, $class ) {

    $html = "
        <div class='field'>
            <em>{$label}: </em> $value
        </div>
    ";

    return $html;

}, 10, 8 );

If you wanted to restrict this to a particular Gravity Form you could use this snippet:

add_action( 'gfpdf_field_html_value', function( $html, $value, $show_label, $label, $field, $form, $entry, $class ) {

    if ( 10 == $form['id'] ) {
        $html = "
            <div class='field'>
                <em>{$label}: </em> $value
            </div>
        ";
    }

    return $html;

}, 10, 8 );

And if you wanted to only change the mark-up for a specific field type you could include this snippet:

add_action( 'gfpdf_field_html_value', function( $html, $value, $show_label, $label, $field, $form, $entry, $class ) {

    if ( 'textarea' == $field->type ) {
        $html = "
            <div class='textarea-field'>
                $value
            </div>
        ";
    }

    return $html;

}, 10, 8 );

Or you can remove any Hidden field types from the PDF entirely:

add_action( 'gfpdf_field_html_value', function( $html, $value, $show_label, $label, $field, $form, $entry, $class ) {

    if ( 'hidden' === $field->type ) {
        return '';
    }

    return $html;

}, 10, 8 );

You can also include additional field information by using our DOM manipulation library, QueryPath. In this example we include a field’s description below the label:

add_action( 'gfpdf_field_html_value', function( $html, $value, $show_label, $label, $field, $form, $entry, $class ) {

    /* Check if the field has a description */
    if ( isset( $field->description ) && 0 < strlen( $field->description ) ) {

        /*
         * We're using the new `GFPDF\\Helper\\Helper_QueryPath` class.
         * It acts like jQuery for PHP which makes it very handy
         */
        $qp = new GFPDF\Helper\Helper_QueryPath();
        $wrapper = $qp->html5( $html );

        /* Insert our description after the field label */
       $description = $qp->html5( '<br>' . wp_kses_post( $field->description ) );
       $wrapper->find( '.label strong' )->after( $description );

        /*
         * Query Path likes to make valid HTML from fragments like we passed, which means the HTML we need is inside '<html><body></body></html>' tags
         * To fix this we'll extract the innerHTML of the <body> tag
         */
        return $wrapper->top( 'html' )->innerHTML5();
    }

    /* If there is no description we'll just return the HTML as is */
    return $html;
}, 10, 8 );

Source Code #source-code

This filter is located in the Helper_Abstract_Fields::html() method of /src/helper/abstract/Helper_Abstract_Fields.php.

Signup for the latest Gravity PDF news, tips and updates

  • This field is for validation purposes and should be left unchanged.
Scroll To Top

Choose your currency:

Close
Converted prices are for reference only - all orders are charged in $ Australian Dollars ($) AUD.
  • AUDAustralian Dollars ($)
  • USDUS Dollars ($)
  • CADCanadian Dollars ($)
  • EUREuros (€)
  • GBPPound Sterling (£)
  • NZDNew Zealand Dollar ($)
  • JPYJapanese Yen (¥)