• Resolved milogcsetc

    (@milogcsetc)


    I’ve built a form that allows a user to customize a unit with options that are offered in radio buttons and checkboxes. I’m trying to build a custom-template PDF invoice that checks to see if a given option is selected in its entry, then outputs a table row of condensed information about each option if it was selected.

    So far, the form is doing great with radio buttons but I can’t get any selected checkboxes to print. Here’s my template php, this one is for a single checkbox in Field 109:

    <?php if (substr($form_data['field'][109],0,7) == 'APX-AMC') { ?> <tr><td>1</td><td>APX-AMC</td><td>APX Master Clock</td><td>$1750</td><td>$1750</td></tr> <?php }; ?>

    In the wp_rg_lead_detail table for my test entry I see that the field_number is 109.1, but adding that to the above doesn’t work. What am I doing wrong? I have some fields with multiple checkboxes, so if you could show me that template too, that would be greatly appreciated. Thanks!

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

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

    (@blue-liquid-designs)

    Hi,

    Checkbox fields are stored in an array in PHP. To check if a value was checked like you want you should loop through the array:

    foreach ( $form_data['field'][109] as $item ) {
      if ( substr( $item, 0, 7) == 'APX-AMC' ) {
         //do stuff here
      }
    }

    If you know the exact name of the checkbox item you can just do an in_array() check and forgo the foreach loop.

    if ( in_array( 'APX-AMX-BLAH-BLAH', $form_data['field'][109] ) ) {
       //do stuff here
    }
    Thread Starter milogcsetc

    (@milogcsetc)

    Thanks! Unfortunately, neither method worked for me. I might be mangling code somewhere:

    <?php if ( in_array( 'APX-AMC: Advanced', $form_data['field'][109] ) ) { ?><tr><td>1</td><td>APX-AMC</td><td>Advanced</td><td>$100</td><td>$100</td></tr><?php }; ?>

    Although I may not be getting the value correct — I don’t see how as I’m copying it directly from the field in wp_rg_lead_detail — when I make it a negative statement then the html appears:

    <?php if ( ! in_array( 'APX-AMC: Advanced', $form_data['field'][109] ) ) { ?><tr><td>1</td><td>APX-AMC</td><td>Advanced</td><td>$0</td><td>$0</td></tr><?php }; ?>
    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    You can review the $form_data array by adding &data=1 to the URL when viewing the PDF by your admin area. You’ll be able to find exactly what information is available in the array and its format.

    Thread Starter milogcsetc

    (@milogcsetc)

    I ran &data=1, and the only mention of this field was just [109] =>

    Only two of my checkbox field options have text after the “=>”

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    That suggests that entry doesn’t have anything selected for field 109. Double check you’ve selected something for that field in the entry you are testing and try again.

    Thread Starter milogcsetc

    (@milogcsetc)

    AMC is visible when I look at my test invoice’s PDF in the default view, and the wp_rg_lead_detail record for the entry lists the option as “109.1” and “APX-AMC: Advanced|100”

    Should the price be included in in_array( '', ? Am I looking in the wrong place for the correct field names and values?

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Ah, it’s a product field. They are located in the $form_data['products'] array key.

    Thread Starter milogcsetc

    (@milogcsetc)

    Oh, that makes sense! I couldn’t find much about the products key — should there more to it than replacing field with products in the coding above? Because I couldn’t get any of them to print. Sorry for being such a pain.

    <?php if ( in_array( 'APX-AMC: Advanced', $form_data['products'][109] ) ) { ?><tr><td>1</td><td>APX-AMC</td><td>Advanced</td><td>$100</td><td>$100</td></tr><?php }; ?>

    Thread Starter milogcsetc

    (@milogcsetc)

    Figured it out! In case anyone ever has this problem too, this is how I did it:

    <table><tbody>
    <?php foreach ($form_data['products'] as $product) { ?>
    <?php foreach ($product['options'] as $option) { ?>
    	<!-- add your checkbox rows -->
    	<?php if (($option['field_label'] == 'name of your pricing checkbox field here') && (substr($option['option_name'], 0, 15) == 'the first 15 digits of the label of your first checkbox in this field')) { ?>
    		<tr><td>1</td><td>2</td><td>3</td></tr>
    	<?php } ?>
    	<?php if (($option['field_label'] == 'name of your pricing checkbox field here') && (substr($option['option_name'], 0, 15) == 'the first 15 digits of the label of your second checkbox in this field')) { ?>
    		<tr><td>4</td><td>5</td><td>6, etc.</td></tr>
    	<?php } ?>
    <?php } ?>
    <?php } ?>
    	<!-- while we're here, this is how I added pricing radio buttons -->
    <?php if (substr($form_data['field'][47], 0, 7) == 'first seven digits of the first button value in field 47') { ?>
    	<tr><td>1</td><td>2</td><td> 3</td></tr><?php } ; ?>
    <?php if (substr($form_data['field'][47], 0, 7) == 'first seven digits of the first button value in field 47') { ?>
    	<tr><td>4</td><td>5</td><td>3</td></tr>
    <?php } ; ?>
    <tbody></table>
    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Glad to hear you worked it out!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Correct syntax for pullingcheck box data?’ is closed to new replies.