Ask your WordPress questions! Pay money and get answers fast! (more info)

Gravity Form Checkbox in GravityPDF

  • SOLVED

I'm trying to display a checkbox from a GravityForm in GravityPDF, I only have one choice on the checkbox i.e. it's ticked or not ticked. I have 20 plus single check box entries (see attached image) all of which need to outputting on a separate line.

GravityPDF uses $form_data['field'][65] to output the checkbox field for example this is field 65.

I have tried the following:

if ( in_array( 'Down Time', $form_data['field'][65] ) ) {
//display checkbox image here, or output <input type="checkbox" checked />
} else {
//display checkbox image here, or output <input type="checkbox" />
}


this works for when the checkbox is ticked but if it's unticked I get an error message

<blockquote>"Warning: in_array() expects parameter 2 to be array, string given in
***/****/***/PDF_EXTENDED_TEMPLATES/hello-world.php"
on line 986"</blockquote>

Then I tried adding a random choice to give it 2 parameters (not sure if this is right)


if ( in_array( 'Down Time','xyz', $form_data['field'][65] ) ) {

echo 'ticked';
//display checkbox image here
} else {
//display checkbox image here

echo 'unticked';
}


Again I get the error message as above.

I've tried lots of other code examples using both in_array and is_array examples and I always get errors. Sometimes its works (or looks like it does) and I get no error but I don't get the right result i.e the box is ticked and it outputs it's unticked or the other way round.

I'm tearing my hair out and need help. Is there any coders out there that can help me.

Simply put I need to output every checkbox on my form to GravityPDF regardless if it's ticked or not and I'll be swapping the result to an image ( checkbox ticked or not ticked) dependant on what the result is.

Answers (1)

2016-08-23

Arnav Joy answers:

please try this

if ( in_array( 'Down Time', $form_data['field'][65] ) && is_array( $form_data['field'][65] ) ) {

//display checkbox image here, or output <input type="checkbox" checked />

} else {

//display checkbox image here, or output <input type="checkbox" />

}


Kennyboy7 comments:

Hi Arnav,

I've tried this and it's exactly the same.

The code you provided:

<?php

if ( in_array( 'Down Time', $form_data['field'][65] ) && is_array( $form_data['field'][65] ) ) {



//display checkbox image here, or output <input type="checkbox" checked />

echo '<div class="checked"></div> ';

} else {

//display checkbox image here, or output <input type="checkbox" />

echo '<div class="unchecked"></div> ';

}

?>



I added my css to change the result to my images ( could this be the issue ??)