Middleware is a term used to define a bridge between two operations. In this case, our middleware is used as the bridge between our form fields and whether they should show up in our Core or Universal PDF templates. If a middleware filter returns
true the field will be skipped.
By default, we have five tests in place to determine if a field should be skipped. These include if the CSS class 'exclude' is added to the field, if the conditional logic passes, if the field is a product or HTML field or if it's apart of our blacklist – by default that is Captchas, Password and Page fields (Page fields are handled separately).
This filter allows you to remove any of the existing middleware or add new conditions to determine if a field should be displayed. The important part to remember about working with the field middleware is that filters should only return
true if the field should be skipped. If it should not be skipped, you just return the
$action to let the middleware process continue.
$action | boolean
trueif the field should be skipped,
$field | GF_Field
- The current field being processed
$entry | array
- The raw Gravity Form Entry array.
$form | array
- The Gravity Forms array
$config | array
- The current settings for the PDF being generated
$products | Field_Products
- The special products object that handles the processing of product fields
$blacklisted | array
- A list of fields that should be skipped (handled in its own middleware)
This snippet shows you can how can remove existing field middleware. In this case, we are removing the conditional logic checks we do on each field in the PDF:
This snippet shows you how you can add your own restrictions and prevent Paragraph fields from being displayed:
This filter is located in the
generate_html_structure() method of