• Resolved viperboys

    (@viperboys)


    Hi, First of all I want to thank you for this magnificent complement that has been of great help to me.

    I am having a issue printing a field of type list. I am creating a custom template. I use this so that the title of each column is dynamic. https://gravitywiz.com/documentation/gravity-forms-populate-anything/#live-merge-tags So when I print that list field in my report, the name of each column appears with the shortcode. The way I use to print it is simply with the shortcode. It is very rare because with the topics that already exist, it prints the list field well. I may be missing add something.

    The page I need help with: [log in to see the link]

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

    (@blue-liquid-designs)

    Hi there,

    To provide any guidance about how to fix I’d need to know what code you are using to display the list in your custom template, what the PDF output looks like, and the specific structure and settings of the list field in your Gravity Form.

    Thread Starter viperboys

    (@viperboys)

    This is my code

    <?php
    
    /*
    * Template Name: Orden de Servicio
    * Version: 2.4
    * Description: A custom PDF template designed specifically for the "Badshahweb" Gravity Form.
    * Author: Gravity PDF
    * Author URI: https://gravitypdf.com
    * Group: Orden de Servicio
    * Required PDF Version: 4.0-alpha
    */
    
    /* Prevent direct access to the template */
    if ( ! class_exists( 'GFForms' ) ) {
        return;
    }
    
    /*
    * All Gravity PDF 4.x templates have access to the following variables:
    *
    * $form (The current Gravity Form array)
    * $entry (The raw entry data)
    * $form_data (The processed entry data stored in an array)
    * $settings (the current PDF configuration)
    * $fields (an array of Gravity Form fields which can be accessed with their ID number)
    * $config (The initialised template config class – eg. /config/zadani.php)
    * $gfpdf (the main Gravity PDF object containing all our helper classes)
    * $args (contains an array of all variables - the ones being described right now - passed to the template)
    */
    
    $f = function( $fid, $newline = true ) use ( $form_data, $fields ) {
        if ( $newline ) {
            echo '  ';
        }
    
        switch ( $fields[ $fid ]['type'] ) {
    
            case 'address':
                $data = $form_data['field'][ $fid ];
    
                $line   = [];
                $line[] = $data['street'];
                $line[] = $data['street2'];
                $line[] = implode( ', ', array_filter( [ $data['city'], $data['state'] ] ) ) . ' ' . $data['zip'];
                $line[] = $data['country'];
                echo implode( '<br>', array_filter( $line ) );
            break;
    
            case 'fileupload':
                $file = $form_data['field'][ $fid ][0];
                if ( strlen( $file ) > 0 ) {
                    echo '<a href="' . $file . '">Download File</a>';
                }
            break;
    
            default:
                echo $form_data['field'][ $fid ];
        }
    
    };
    
    ?>
    <style>
    @page {
            header: html_pageHeader;
            footer: html_pageFooter;
            margin: 0mm 27mm;
        }
    
        p {
            margin: 0 0 27  mm;
            padding: 0;
        }
    
        a {
            color: blue;
        }
    
        /* Header / Footer */
        header {
            text-align: center;
            padding-bottom: 6mm;
        }
    
        footer {
            text-align: center;
        }
    
        /* Heading */
        h3 {
            margin: 0;
            padding: 2mm 0;
            font-size: 100%;
        }
    
        /* Tables */
        egt {
            border: 1px ;
            padding: 1.5mm;
            vertical-align: middle;
        }
    
        table {
            margin: 3mm 1mm;
        }
    
        th {
            text-align: left;
        }
    
        td {
            border: 1px solid #c3c3c3;
            padding: 1.5mm;
            vertical-align: middle;
             width: 100px;
        }
    
        .no-border td {
            border: none;
            padding: 0;
        }
    
    thead tr td{
    text-align:left;
     font-weight:bold;
     font-size:15px;
    }
    tbody tr td, .top-finel_row table tr td{
    text-align:left;
    }
    
    span{
     font-weight:bold;
    }
    
    .column {
      float: left;
      width: 23%;
    
    }
    .column2 {
      float: left;
      width: 50%;
      }
    
    .column1 {
      float: left;
      width: 100%;
      }
    
    /* Clear floats after the columns */
    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    
    </style>
    
    <!-- Begin HTML -->
    <htmlpageheader name="pageHeader">
        <header>
    
        <table>
          <tr>
            <td style= "text-align: center;"><h3>NIT= 900.753.535-4 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ORDEN DE SERVICIO</h3></td>
    
            <td style= "text-align: center;"><div> <img style="width:15%;"  src="<?php echo __DIR__; ?>/images/logosPacco.png"></div></td>
          </tr>
        </table>
    
        </header>
    </htmlpageheader>
    
    <htmlpagefooter name="pageFooter">
        <footer>
    
        <table style= "background-color: #ebebeb;">
         <tr>
          <td style= "text-align: center; background-color: #ebebeb;" colspan="5"><span>SEPARAR PARA SIGUIENTE PROCESO</span></td>
          <td rowspan="6">REFERENCIA ENTREGADA POR MARMOL PARA RUIMAR</td>
         </tr>
         <tr style = "background-color: #ebebeb;">
          <td style= "text-align: center;"><span>PROCESO</span></td>
          <td style= "text-align: center;"><span>PIEZA</span></td>
          <td style= "text-align: center;"><span>ENTRETELA</span></td>
          <td style= "text-align: center;"><span>CONTACTO</span></td>
          <td style= "text-align: center;"><span>TELEFONO</span></td>
    
         </tr>
         <tr style="">
          <td height="30"></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
    
         </tr>
         <tr>
          <td style= "text-align: center;" colspan="2"><span>TRANSPORTADOR</span></td>
    
          <td></td>
          <td style= "text-align: center;"><span>TELEFONO</span></td>
          <td></td>
    
         </tr>
         <tr>
          <td style= "text-align: center;" colspan="5"><span>OBSERVACIONES</span></td>
    
         </tr>
         <tr>
          <td colspan="5">ADELANTAR MUESTRAS FISICAS PARA SER APROBADA POR EL COMERCIAL DANIEL GIRALDO,PARA PODER ARRANCAR CON EL PROCESO</td>
    
         </tr>
        </table>
    
        </footer>
    </htmlpagefooter>
    
        <table style = "background-color: #ebebeb;">
          <tr>
            <td HEIGHT="60" style= ""><span>CLIENTE</span></td>
            <td colspan="2"style= "">PACCO</td>
            <td style= ""><span>REFERENCIA</span></td>
            <td style= "">TS MARO NAC Y TS SKULL2</td>
            <td style= ""><span>LOTE</span></td>
            <td style= "">10353</td>
            <td style= ""><span>OC</span></td>
            <td style= ""></td>
            <td colspan="2"style= ""><span>N° ORDEN</span></td>
            <td style= ""></td>
          </tr>
          <tr>
            <td colspan="2"style= ""><span>DESCRIPCIÓN</span></td>
            <td colspan="7" style= ""></td>
            <td colspan="2"style= ""><span>FECHA DE ENTREGA AL ESTAMPADO</span></td>
            <td style= ""></td>
          </tr>
          <tr>
            <td style= ""><span>PROCESO</span></td>
            <td colspan="2" style= ""></td>
            <td style= ""><span>UNIDADES</span></td>
            <td style= ""></td>
            <td style= ""><span>VALOR UNI</span></td>
            <td style= ""></td>
            <td style= ""><span>VALOR TOTAL</span></td>
            <td style= ""></td>
            <td colspan="2"style= ""><span>FECHA DE ENTREGA A PACCO</span></td>
            <td style= ""></td>
          </tr>
          <tr>
            <td HEIGHT="60" colspan="2"style= ""><span>PROVEEDOR</span></td>
            <td colspan="4" style= ""></td>
            <td colspan="2" style= ""><span>CONTACTO</span></td>
            <td colspan="2"style= ""></td>
            <td style= ""><span>TELEFONO</span></td>
            <td style= ""></td>
          </tr>
        </table>
    
        <table style = "background-color: #ebebeb;">
              <tr>
                <td HEIGHT="50" style= "text-align: center;" colspan="9"><span>LIQUIDACIÓN DE CORTE</span></td>
              </tr>
              <tr>
                <td>REFERENCIA TELA</td>
                <td colspan="3"></td>
                <td>CANTIDAD TELA</td>
                <td></td>
                <td>LIQUIDAR TELA</td>
                <td></td>
              </tr>
              <tr>
                <td>CONSUMO ESTIMADO</td>
                <td></td>
                <td>CONSUMO REAL</td>
                <td></td>
                <td>TOTAL TELA</td>
                <td></td>
                <td>NO LIQUIDAR TELA</td>
                <td></td>
    
              </tr>
    
    </table>
    <p></p>
    
    <?php
    //$f( 45 );
    $location= $form_data['field'][45];
    if ( $location === 'General' ): ?>
       <table style = "background-color: #ebebeb;">
               <tr>
                <td>COLOR</td>
                <td>Talla XS</td>
                <td>Talla S</td>
                <td>Talla M</td>
                <td>Talla L</td>
                <td>Talla XL</td>
                <td>Talla XXL</td>
                <td>Talla XXXL</td>
    
              </tr>
    
    </table>
    <?php endif; ?>
    <?php
    //$f( 45 );
    $location= $form_data['field'][45];
    if ( $location === 'Infantil Junior' ): ?>
       <table style = "background-color: #ebebeb;">
               <tr>
                <td>COLOR</td>
                <td>Talla 4</td>
                <td>Talla 6</td>
                <td>Talla 8</td>
                <td>Talla 10</td>
                <td>Talla 12</td>
                <td>Talla 14</td>
                <td>Talla 16</td>
                <td>Talla 18</td>
                <td>Talla 20</td>
                <td>Talla 22</td>
                <td>Talla 24</td>
    
              </tr>
    
    </table>
    <?php endif; ?>
    <?php
    //$f( 45 );
    $location= $form_data['field'][45];
    if ( $location === 'Bebé' ): ?>
       <table style = "background-color: #ebebeb;">
               <tr>
                <td>COLOR</td>
                <td>Talla 6M</td>
                <td>Talla 9M</td>
                <td>Talla 12M</td>
                <td>Talla 18M</td>
                <td>Talla 24M</td>
                <td>Talla 2T</td>
                <td>Talla 3T</td>
                <td>Talla 4T</td>
                <td>Talla 5T</td>
                </tr>
    
    </table>
    <?php endif; ?>
    <?php
    //$f( 45 );
    $location= $form_data['field'][45];
    if ( $location === 'Adulto' ): ?>
       <table style = "background-color: #ebebeb;">
               <tr>
                <td>COLOR</td>
                <td>Talla 28</td>
                <td>Talla 30</td>
                <td>Talla 32</td>
                <td>Talla 34</td>
                <td>Talla 36</td>
                <td>Talla 38</td>
                <td>Talla 40</td>
                <td>Talla 42</td>
                <td>Talla 44</td>
                <td>Talla 46</td>
                <td>Talla 48</td>
                </tr>
    
    </table>
    <p>{Cantidad pedida:124:}</p>
    <?php endif; ?>
    
        <?php
        $list_values = unserialize( rgar( $entry, '124' ) );
    
        //GFFormsModel::get_lead_field_value( $entry, $list_values);
    /*
        echo '<table border="1">';
        foreach ($list_values as $key => $value) :
            echo '<tr>';
            for($indice=0; $indice<count($valor); $indice++):
                echo "Cordenadas ->".key."-".$indice."Valor ->".$valor[$indice];
            endfor;
            echo '</tr>';
        endforeach;
        echo '</table>';*/
        //print_r($list_values);
    
        print contarFilas($list_values);
    
        function contarFilas($arreglo){
    
        //$cantidad = 0;
    
        echo '<table style="margin-top: -100px; position: relative;" border="1">';
        foreach($arreglo as $elemento){
            //$cantidad ++;
            echo '<tr>';
                    foreach ( $elemento as $v) {
                    if ($v != ""){
                    echo '<td WIDTH="10">';
    
                    echo $v;
                   }
                    echo '</td>';
                    }}
            echo '</tr>';
        echo '</table>';
       return $cantidad;
    }
    
        //$f( 124 );
    
        ?>

    In line 379 I add the marge tag.

    This is the result
    https://textilesryr.luxflow.app/pdf/62cc67c56d369/767/

    Color
    Cant Talla
    @{Campo
    1:87:fallba
    ck[*]}
    Cant Talla
    @{Campo
    2:93:fallba
    ck[*]}
    Cant Talla
    @{Campo
    3:92:fallba
    ck[*]}
    Cant Talla
    @{Campo
    4:91:fallba
    ck[*]}
    Cant Talla
    @{Campo
    5:90:fallba
    ck[*]}
    Cant Talla
    @{Campo
    6:89:fallba
    ck[*]}
    Cant Talla
    @{Campo
    7:88:fallba
    ck[*]}
    Cant Talla
    @{Campo
    8:94:fallba
    ck[*]}
    Cant Talla
    @{Campo
    9:95:fallba
    ck[*]}
    Cant Talla
    @{Campo
    10:96:fallb
    ack[*]}
    Cant Talla
    @{Campo
    11:97:fallb
    ack[*]}
    Cant Talla
    @{Campo
    12:98:fallb
    ack[*]}

    This is bad..

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Thanks for that.

    What is the full contents of $list_values = unserialize( rgar( $entry, '124' ) ); if you do a print_r( $list_value );exit; in your template?

    Also, what if you do the same with the processed $form_data info: print_r( $form_data['list'][124] ); exit;?

    Thread Starter viperboys

    (@viperboys)

    Hi,
    Also, what if you do the same with the processed $form_data info: print_r( $form_data[‘list’][124] ); exit;?
    This is the result
    Array ( [0] => Array ( [Color] => jverde [Cant Talla @{Campo 1:87:fallback[*]}] => 5 [Cant Talla @{Campo 2:93:fallback[*]}] => 7 [Cant Talla @{Campo 3:92:fallback[*]}] => 10 [Cant Talla @{Campo 4:91:fallback[*]}] => 11 [Cant Talla @{Campo 5:90:fallback[*]}] => 12 [Cant Talla @{Campo 6:89:fallback[*]}] => 13 [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) [1] => Array ( [Color] => Rojo [Cant Talla @{Campo 1:87:fallback[*]}] => 2 [Cant Talla @{Campo 2:93:fallback[*]}] => 3 [Cant Talla @{Campo 3:92:fallback[*]}] => 5 [Cant Talla @{Campo 4:91:fallback[*]}] => 5 [Cant Talla @{Campo 5:90:fallback[*]}] => 4 [Cant Talla @{Campo 6:89:fallback[*]}] => 5 [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) [2] => Array ( [Color] => amarillo [Cant Talla @{Campo 1:87:fallback[*]}] => 1 [Cant Talla @{Campo 2:93:fallback[*]}] => 5 [Cant Talla @{Campo 3:92:fallback[*]}] => 5 [Cant Talla @{Campo 4:91:fallback[*]}] => 2 [Cant Talla @{Campo 5:90:fallback[*]}] => [Cant Talla @{Campo 6:89:fallback[*]}] => [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) [3] => Array ( [Cant Talla @{Campo 1:87:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>8</strong></div> [Cant Talla @{Campo 2:93:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>15</strong></div> [Cant Talla @{Campo 3:92:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>20</strong></div> [Cant Talla @{Campo 4:91:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>18</strong></div> [Cant Talla @{Campo 5:90:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>16</strong></div> [Cant Talla @{Campo 6:89:fallback[*]}] => <div style='border-top: medium double; border-bottom: 1px solid;'><strong>18</strong></div> ) )

    What is the full contents of $list_values = unserialize( rgar( $entry, ‘124’ ) ); if you do a print_r( $list_value );exit; in your template?

    Array ( [0] => Array ( [Color] => jverde [Cant Talla @{Campo 1:87:fallback[*]}] => 5 [Cant Talla @{Campo 2:93:fallback[*]}] => 7 [Cant Talla @{Campo 3:92:fallback[*]}] => 10 [Cant Talla @{Campo 4:91:fallback[*]}] => 11 [Cant Talla @{Campo 5:90:fallback[*]}] => 12 [Cant Talla @{Campo 6:89:fallback[*]}] => 13 [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) [1] => Array ( [Color] => Rojo [Cant Talla @{Campo 1:87:fallback[*]}] => 2 [Cant Talla @{Campo 2:93:fallback[*]}] => 3 [Cant Talla @{Campo 3:92:fallback[*]}] => 5 [Cant Talla @{Campo 4:91:fallback[*]}] => 5 [Cant Talla @{Campo 5:90:fallback[*]}] => 4 [Cant Talla @{Campo 6:89:fallback[*]}] => 5 [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) [2] => Array ( [Color] => amarillo [Cant Talla @{Campo 1:87:fallback[*]}] => 1 [Cant Talla @{Campo 2:93:fallback[*]}] => 5 [Cant Talla @{Campo 3:92:fallback[*]}] => 5 [Cant Talla @{Campo 4:91:fallback[*]}] => 2 [Cant Talla @{Campo 5:90:fallback[*]}] => [Cant Talla @{Campo 6:89:fallback[*]}] => [Cant Talla @{Campo 7:88:fallback[*]}] => [Cant Talla @{Campo 8:94:fallback[*]}] => [Cant Talla @{Campo 9:95:fallback[*]}] => [Cant Talla @{Campo 10:96:fallback[*]}] => [Cant Talla @{Campo 11:97:fallback[*]}] => [Cant Talla @{Campo 12:98:fallback[*]}] => ) )

    Sorry for the delayed response. I was indisposed.

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Thanks for providing all those details.

    Try this for outputting your list field and see if that works for you:

    
    echo '<table border="1">';
    foreach( $form_data['list'][124] as $key => $row ) {
    	/* Output the table header */
    	if( $key === 0 ) {
    		echo '<tr>';
    		foreach( array_keys( $row ) as $column ) {
    			echo "<th>$column</th>";
    		}
    		echo '</tr>';
    	}
    
    	echo '<tr>';
    	foreach( array_values( $row ) as $column ) {
    		echo "<td>$column</td>";
    	}
    	echo '</tr>';
    }
    echo '</table>';
    
    • This reply was modified 1 year, 8 months ago by Jake Jackson. Reason: code formatting
    Thread Starter viperboys

    (@viperboys)

    Hi Jake,
    Now it looks much better..All that remains is to add the totals of each column in the last row. Check how it looks now.

    Color Cant Talla XS Cant Talla S Cant Talla M Cant Talla L Cant Talla XL Cant Talla
    XXL
    Cant Talla
    XXXL Cant Talla * Cant Talla * Cant Talla * Cant Talla * Cant Talla *
    Rojo 1 11 1 1 1
    cds
    <div
    style='border-
    top: medium
    double;
    border-
    bottom: 1px
    solid;'><stron
    g>1</strong
    ></div>
    <div
    style='border-
    top: medium
    double;
    border-
    bottom: 1px
    solid;'><stron
    g>11</strong
    ></div>
    <div
    style='border-
    top: medium
    double;
    border-
    bottom: 1px
    solid;'><stron
    g>1</strong
    ></div>
    <div
    style='border-
    top: medium
    double;
    border-
    bottom: 1px
    solid;'><stron
    g>1</strong
    ></div>
    <div
    style='border-
    top: medium
    double;
    border-
    bottom: 1px
    solid;'><stron
    g>1</strong
    ></div>

    For some reason it adds html code.

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Sounds like you are using GravityWP’s List Number Format plugin. You can strip the HTML from those totals using wp_strip_all_tags(). If the HTML is already encoded, you can decode it first with wp_specialchars_decode().

    Thread Starter viperboys

    (@viperboys)

    Hi Jake,

    I have managed to print the list with this code.

    echo '<table border="1">';
        foreach( $form_data['list'][124] as $key => $row ) {
        /* Output the table header */
        if( $key === 0 ) {
            echo '<tr>';
            foreach( array_keys( $row ) as $column ) {
                $stript_column = wp_strip_all_tags(wp_specialchars_decode($column));
                echo "<th>$stript_column</th>";
            }
            echo '</tr>';
        }
    
        echo '<tr>';
    
        foreach( array_values( $row ) as $column ) {
            $stript_column = wp_strip_all_tags(wp_specialchars_decode($column));
    
            echo "<td>$stript_column</td> ";
        }
        echo '</tr>';
    }
    echo '</table>';

    But now I face another challenge. The row that prints the totals is printed one cell to the left.

    Check https://textilesryr.luxflow.app/pdf/62cc67c56d369/851/

    Can you help me with this?

    Thank you..

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Hard to say without seeing the exact structure of the list array, but my guess is you could test for the last $key in the list and then add an extra table cell to align them correctly.

    As for the exact code to do this, that’s unfortunately outside of the free support we provide users. If you need help with custom template development we offer a paid development service.

    Thread Starter viperboys

    (@viperboys)

    Hi, I already managed to do it!

    echo '<table border="1">';
    
    $lastkey=contarFilas($form_data['list'][124]);
    
    function contarFilas($arreglo){
    
        $cantidad = 0;
    
        foreach($arreglo as $elemento){
            $cantidad ++;
        }
    
           return $cantidad -1;
    }
        foreach( $form_data['list'][124] as $key => $row ) {
        /* Output the table header */
        if( $key === 0 ) {
            echo '<tr>';
            foreach( array_keys( $row ) as $column ) {
                $stript_column = wp_strip_all_tags(wp_specialchars_decode($column));
                echo "<th>$stript_column</th>";
            }
            echo '</tr>';
        }
    
        echo '<tr>';
        if( $key === $lastkey ) {
            echo '<td></td>';
    }
        foreach( array_values( $row ) as $column ) {
            $stript_column = wp_strip_all_tags(wp_specialchars_decode($column));
            echo "<td>$stript_column</td> ";
        }
        echo '</tr>';
    }
    echo '</table>';

    Thanks for everything.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘I have a issue with list field’ is closed to new replies.