Empty values still shown when label set [RESOLVED]

Hello,

I have a form set up with fields including a label and a value.
If the label is set to a string but the value is left empty, I still get those fields in my PDF.

I would expect not to see these fields when having the parameter “show empty fields” turned off.

I hope you can help me fix this.

Hi Leo. Rather than having an empty first option, can you use the Placeholder on the Appearance tab, to set the placeholder as “keine” and then remove that blank first option?

Hi Chris.
That leaves me with the problem of the user not being able to switch back from a set value > 0 to “keine”.
At least that’s what I believe, correct?

Thanks for your help already.

I can’t tell from the screenshot what type of field that is. Is that a radio button field?

It’s a Drop Down field (german ‘Auswahlfeld’).

Hi Leo. Which plugin are you using to create the PDF? Have you checked with their support to see about how to exclude empty fields?

I use Gravity PDF with the Zadani template. Isn’t that the tool that you provide?

No, Gravity PDF is a separate company. They have awesome support. I recommend contacting them for assistance.

Hey Leo,

Jake from Gravity PDF here.

Displaying the field label in the PDF is the default. If you’d like to show the value instead the easiest way is to use our Core Booster extension. If you’re a developer you can also search our documentation and use our filter(s) to disable this as well.

1 Like

Thanks @Jake_Jackson for the hint towards your documentation.
So what I did was to use:

add_filter( 'gfpdf_pdf_field_content', function( $value, $field, $entry, $form ) {
	if($value=="kein"){
		$value="";
	}
	return $value;
}, 10, 4 );

to replace the ‘kein’ labels with an empty string. But as they are still shown in the final PDF (even though Show Empty Fields is OFF) it seems that the decision if a field is empty and therefore to be excluded or not is made before that filter is applied.

Is there a way around that?

1 Like

Thanks for the additional information. I believe the gfpdf_field_middleware filter is what you’re looking for: https://docs.gravitypdf.com/v5/gfpdf_field_middleware. You’ll be able to programically exclude this field when the value is kein.

1 Like

Thanks again @Jake_Jackson.

What I tried was this filter:

add_filter( 'gfpdf_field_middleware', function( $action, $field, $entry, $form, $config, $products, $blacklisted ) {
	if ( $action === false ) {
		if ( $entry['1'] == 'kein' ) {
			return true;
		}
	}
	return $action;
}, 10, 7 );

As there is no $value I could check for “kein” I went for that $entry array. But I think I made a mistake here.
Any way to help me out on this?

1 Like

Sure! Two things:

  1. You will want to apply this to a single field only by checking $field->id
  2. The entry will store the value of your field and not the label. You can use print_r( $entry ) to inspect the entry object and see exactly what to target.
1 Like

Alright.
That did the trick for me:

add_filter( 'gfpdf_field_middleware', function( $action, $field, $entry, $form, $config, $products, $blacklisted ) {
	if ( $action === false ) {
		if ($field->type == 'select') {
				if ( $entry[$field->id] == '' ) {
						return true;
				}
		}
	}
	return $action;
}, 10, 7 );

To check if the value (not the label) is empty and to then exclude that field is something I would expect from the “exclude empty fields” option (or maybe a choice if label or value is to be checked). Otherwise I don’t see the point in having a seperate label and value field (at least in this case).

Thank you guys very much for your support. That was really great.

2 Likes
© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.