• Resolved firstusadata

    (@firstusadata)


    Is there any way to use PHP conditional statement to display or hide content in the PDF?

    I have a section on my form where users select either “yes” or “no” to a query. If the user chooses “yes” on this section, more questions pop up in the form via Gravity Forms conditional logic.

    How can I display this content in the PDF only if the user selects “yes” and how can I hide this content in the PDF if the user selects “no”?

    Any help would be much appreciated.

    https://wordpress.org/plugins/gravity-forms-pdf-extended/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Jake Jackson

    (@blue-liquid-designs)

    When developing a custom PDF template you can use the $form_data array in PHP conditional statements.

    For instance:

    if ( 'Yes' == $form_data['field'][20] ) {
       //output anything when field #20 is set to "Yes"
    }
    Thread Starter firstusadata

    (@firstusadata)

    Blue Liquid Designs,

    I tried adding this code into my custom PDF template for a simple test

    <?php if ( 'Yes' == $form_data['field'][25] ) {
       <div>This is a test of the radio toggle</div>
    } ?>

    However my PDF just turns into a blank white screen when I test it. I added the code to dreamweaver and it states there is syntax error on the line with the div content. Can you provide anymore insight into this issue?

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    You jumped into HTML while PHP was open.

    Either stay in PHP and echo/print the HTML:

    <?php if ( 'Yes' == $form_data['field'][25] ) {
       echo '<div>This is a test of the radio toggle</div>';
    } ?>

    Or close PHP, output your HTML and then close the conditional.

    <?php if ( 'Yes' == $form_data['field'][25] ): ?>
        <div>This is a test of the radio toggle</div>
    <?php endif; ?>
    Thread Starter firstusadata

    (@firstusadata)

    Thank you very much for your reply, I should have realized that error myself.

    If the form field were to be a dropdown list instead of a radio toggle, would I still use this similar function? Just include the List’s Item Name instead of ‘Yes’ ?

    To clarify, I have a dropdown list where the user selects their industry keyword type. Depending on this selection, a unique image is added to the PDF.
    I tried accomplishing this with the method above, but it did not work.

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Yes. It’s the exact same principal (provided your Dropdown isn’t set to the multi option).

    Thread Starter firstusadata

    (@firstusadata)

    Jake Jackson,

    Thank you for all of the information you have been able to provide regarding my issue. I was able to get my radio toggle to properly show depending on the input. I would like to add similar functionality to a dropdown list.

    My current PHP code looks as such:

    <?php if ($form_data['field'][202] == 'Arts & Music'): ?> Arts & Music Selected <?php else: ?> Arts & Music Not Selected <?php endif; ?>

    And my data array shows:
    `[202.Industry Keyword] => Arts & Music
    [202] => Arts & Music
    [Industry Keyword] => Arts & Music
    [202.Industry Keyword_name] => Arts & Music
    [202_name] => Arts & Music
    [Industry Keyword_name] => Arts & Music`

    However, when I try adding this PHP statement to my custom template, it always displays “Arts & Music Not Selected”

    Is there something that I am missing, or is the issue caused by something else? If you can help me out with this as well that would be perfect.

    Thank you!

    Thread Starter firstusadata

    (@firstusadata)

    I figured it out!

    MY “&” sign seems to have been messing things up.

    Here is my current code in case anyone else runs across this thread.

    <?php if ($form_data['field'][202] == 'Arts and Music'): ?> Arts and Music Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Calpian'): ?> Calpian Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Culinary'): ?> Culinary Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Electronics'): ?> Electronics Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Family and Kids'): ?> Family and Kids Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Fashion'): ?> Fashion Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Financial'): ?> Financial Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Going Green'): ?> Going Green Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Health and Fitness'): ?> Health and Fitness Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Home Decor and Gardening'): ?> Home Decor Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Outdoors'): ?> Outdoors Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Pets and Animals'): ?> Pets and Animals Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Tools'): ?> Tools Selected <?php else: ?>
    <?php endif; ?>
    <?php if ($form_data['field'][202] == 'Travel'): ?> Travel Selected <?php else: ?>
    <?php endif; ?>
    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Glad to hear you worked it out.

    From memory, the & character was probably a HTML entity. If you used its entity equivalent it probably would have worked.

    Thread Starter firstusadata

    (@firstusadata)

    Jake,

    Thank you for all of the help you have been able to provide so far with this issue.

    I had one more question, how would I go about accomplish this:

    I have a dropdown field giving options a, b, c, d, & e. I would like to show one div if either a, b, or c, are selected, and another div if d or e are selected. I tried something like:

    <?php if ($form_data['field'][86] == 'a'or 'b'or 'c'): ?><div>A, B, or C are Selected</div>
    <?php else: ?><div>D or E is selected</div>
    <?php endif; ?>

    But it does not seem to be working for me. I believe this may just be a syntax error on my part, but if there is any advice you could provide, that would be very much appreciated.

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    A switch statement would be better:

    switch( $form_data['field'][86] ) {
       case 'a':
       case 'b':
       case 'c':
          //do something here
       break;
    
       default:
          //do something else here.
       break;
    }
    Thread Starter firstusadata

    (@firstusadata)

    Thank you very much once again Jake.

    And thank you for the awesome plugin!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Show/Hide PDF Content Based on User Selection’ is closed to new replies.