• Resolved Javier E.

    (@javier-e)


    Hi! im using the next code on a custom page template:

    <?php echo do_shortcode('[cfdb-table form="Contacto" filter="submit_time>2015-06-01&&submit_time<2015-06-06"]'); ?>

    If i use just 1 submit_time instead of 2, works perfectly or if i copy only the text shortcode and paste into the wp editor (inside a page) works with the 2 submit_time filters.

    I did some tests and works too with ajax request, example:

    <?php $url = site_url().'/wp-admin/admin-ajax.php?action=cfdb-export&form='.$formulario.'&filter='.implode('%26%26', $filtro).'&content=&enc=HTML&hide=Submitted%20Login,Submitted%20From';
    ?>
    
    <script type="text/javascript">
    						jQuery(document).ready(function($){
    							$.ajax({
    								url: '<?=$url?>',
    								type: 'POST',
    								beforeSend: function(){ },
    								data: $(this).serialize(),
    								success: function(data){
    								$('div.tabla').html(data);
    								}
    							});
    						});
                            </script>

    Thank you!

    https://wordpress.org/plugins/contact-form-7-to-database-extension/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Are you saying it does not work on the custom page template? What do you see?

    Make sure there is no line break in the short code.

    If you add debug="true" into the short code then it will show how it parses the filters.

    Thread Starter Javier E.

    (@javier-e)

    Hi! thanks for your reply!, i added debug=”true” to the shortcode and i see the shortcode like a plain text.

    Anyway, if i use just 1 submit_time like this: [cfdb-table limit="0,50" form="Contacto" filter="submit_time>=2015-06-01" hide="Submitted Login,Submitted From"] it works.

    This is my full code:

    <?php /* Template Name: Exportar Contactos */ ?>
    <?php get_header(); ?>
    <!-- start: #exportar -->
    <main id="exportar" class="main" role="main">
    	<?php if(have_posts()): the_post(); ?>
        	<!-- start: .content -->
            <div class="content">
                <article <?php post_class(); ?>>
                    <header class="interior">
                        <h2 class="title wow fadeInUp"><?php the_title(); ?></h2>
                        <h3 class="wow fadeInUp" data-wow-delay="200ms">Todos los campos son opcionales.</h3>
                        <div class="clear"></div>
                    </header>
    
                    <?php
    					$tipo = 1;
    					$fecha_desde_en = $fecha_hasta_en = $proyecto = '';
    					$filtro = array();
    					if(isset($_GET['tipo'])){
    						$tipo = $_GET['tipo'];
    					}
    					if(isset($_GET['proyecto']) && $_GET['proyecto']){
    						$proyecto = $_GET['proyecto'];
    						$filtro[] = 'Proyecto==='.get_the_title($proyecto);
    					}
    					if(isset($_GET['nombre']) && $_GET['nombre']){
    						$nombre = $_GET['nombre'];
    						$filtro[] = 'stripos(Nombre,'.$nombre.')===0||stripos(Nombre,'.$nombre.')>0';
    					}
    					if(isset($_GET['rut']) && $_GET['rut']){
    						$rut = $_GET['rut'];
    						$filtro[] = 'Rut==='.$rut;
    					}
    					if(isset($_GET['fecha_desde']) && $_GET['fecha_desde']){
    						$f = explode('-', $_GET['fecha_desde']);
    						$fecha_desde_en = $f[2].'-'.$f[1].'-'.$f[0];
    						$filtro[] = 'submit_time>='.$fecha_desde_en;
    					}
    					if(isset($_GET['fecha_hasta']) && $_GET['fecha_hasta']){
    						$fh = explode('-', $_GET['fecha_hasta']);
    						$fecha_hasta_en = $fh[2].'-'.$fh[1].'-'.$fh[0];
    						$filtro[] = 'submit_time<='.$fecha_hasta_en;
    					}
    					switch($tipo){
    						case 1: $formulario = 'Cotización'; break;
    						case 2: $formulario = 'Contacto'; break;
    						case 3: $formulario = 'Servicio al Cliente'; break;
    					}
    
    				?>
                    <section class="post-content center wow fadeIn" data-wow-delay=".6s">
    					<?php
                        if ( post_password_required() ):
                            echo get_the_password_form();
                        else:
                        ?>
                    	<form action="<?php echo site_url(); ?>/exportar" method="get">
                            <div class="clear20"></div>
                        	<div class="input-wrapper">
                            	<label for="tipo">Tipo de Formulario</label>
                                <select name="tipo" id="tipo">
                                    <option value="1" <?php if($tipo == 1) echo 'selected'; ?>>Cotización</option>
                                    <option value="2" <?php if($tipo == 2) echo 'selected'; ?>>Contacto</option>
                                    <option value="3" <?php if($tipo == 3) echo 'selected'; ?>>Servicio al Cliente</option>
                                </select>
                            </div>
                            <div class="input-wrapper">
                            	<label for="fecha_desde">Fecha inicial</label>
                                <input type="text" name="fecha_desde" class="inputbox fecha" id="fecha_desde"  value="<?php echo @$_GET['fecha_desde']; ?>">
                            </div>
                            <div class="input-wrapper last">
                                <label for="fecha_hasta">Fecha limite</label>
                                <input type="text" name="fecha_hasta" class="inputbox fecha" id="fecha_hasta" value="<?php echo @$_GET['fecha_hasta']; ?>">
                            </div>
                            <div class="clear10"></div>
                            <div class="input-wrapper">
                            	<?php
    							$args = array('posts_per_page' => -1, 'post_type' => 'proyectos', 'order' => 'ASC', 'suppress_filters' => false);
    							$proyectos = get_posts($args);
    							?>
                            	<label for="proyecto">Proyecto</label>
                                <select name="proyecto" id="tipo">
                                	<option value="">Todos</option>
                                    <?php foreach($proyectos as $post): setup_postdata($post); ?>
                                    	<option value="<?php echo $post->ID; ?>" <?php if($proyecto == $post->ID) echo 'selected'; ?>><?php the_title(); ?></option>
                                    <?php endforeach; wp_reset_postdata(); ?>
                                </select>
                            </div>
                            <div class="input-wrapper">
                            	<label for="nombre">Nombre (del emisor)</label>
                                <input type="text" name="nombre" class="inputbox" id="nombre"  value="<?php echo @$_GET['nombre']; ?>">
                            </div>
                            <div class="input-wrapper last">
                                <label for="rut">Rut (del emisor)</label>
                                <input type="text" name="rut" class="inputbox" id="rut" value="<?php echo @$_GET['rut']; ?>">
                            </div>
                            <div class="clear10"></div>
                        	<input type="submit" class="button alignright" value="Filtrar">
                            <input type="reset" class="button alignright" value="Limpiar" style="margin-right: 20px;">
                            <div class="clear10"></div>
                        </form>
                        <div class="text">
                        	<?php
    							$current_page = 1;
    							$limit = 50;
    							if(isset($_GET['pagina']) && $_GET['pagina']){
    								$current_page = $_GET['pagina'];
    
    							}
    							$total = do_shortcode('[cfdb-count form="'.$formulario.'" filter="'.implode('&&', $filtro).'"]');
    							$n_pages = ceil($total / $limit);
    							$offset = ($current_page - 1)  * $limit;
    							$start = $offset + 1;
    							$end = min(($offset + $limit), $total);
    							$get = array();
    							$get = $_GET;
    							unset($_GET['pagina']);
    
    							$current_url = '?'.http_build_query($_GET);
    							echo '<div class="paginacion">';
    								echo '<p>Página <strong>'.$current_page.'</strong> de un total de <strong>'.$n_pages.'</strong>.</p>';
    								// The "back" link
    								echo $prevlink = ($current_page > 1) ? '<a href="'.$current_url.'&pagina=1" title="">Primera Página</a> <a href="'.$current_url.'&pagina=' . ($current_page - 1) . '" title="">Anterior</a>' : '<span class="disabled">Primera Página</span> <span class="disabled">Anterior</span>';
    
    								// The "forward" link
    								echo $nextlink = ($current_page < $n_pages) ? '<a href="'.$current_url.'&pagina=' . ($current_page + 1) . '" title="">Siguiente</a> <a href="'.$current_url.'&pagina=' . $n_pages . '" title="">Última Página</a>' : '<span class="disabled">Siguiente</span> <span class="disabled">Última Página</span>';
    
    							echo '</div>';
    							echo ('[cfdb-table debug="true" limit="'.$offset.','.$limit.'" form="'.$formulario.'" filter="'.implode('&&', $filtro).'" hide="Submitted Login,Submitted From"]');
    							echo '<div class="clear10"></div>';
    							echo do_shortcode('[cfdb-export-link form="'.$formulario.'" filter="'.implode('&&', $filtro).'" enc="TSVUTF16LEBOM" linktext="Descargar todos los registros encontrados en Excel" hide="Submitted Login,Submitted From"]');
    						?>
                            <?php the_content(); ?>
                        </div>
                        <div class="clear"></div>
                    </section>
                </article>
            </div>
            <!-- end: .content -->
            <script type="text/javascript">
            (function($){
    			$(document).ready(function($){
    				$('form input[type=reset]').click(function(){
    					$('form .inputbox, form select').not('[name=tipo]').val('');
    					return false;
    				});
    				$('.fecha').pikaday({
    					firstDay: 1,
    					format: 'DD-MM-YYYY',
    					i18n: {
    						previousMonth : 'Mes Anterior',
    						nextMonth     : 'Mes Siguiente',
    						months        : ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
    						weekdays      : ['Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado'],
    						weekdaysShort : ['Dom','Lun','Mar','Mie','Jue','Vie','Sab']
    					}
    				});
    
    			});
    		})(jQuery);
            </script>
            <?php endif; ?>
        <?php endif; ?>
    </main>
    <!-- end: #exportar -->
    <?php get_footer(); ?>

    Of course if i copy and paste the shortcode into the wordpress editor (tinymce) works fine.

    Thank you!

    Thread Starter Javier E.

    (@javier-e)

    Sorry this is the line im using now: echo do_shortcode('[cfdb-table limit="'.$offset.','.$limit.'" form="'.$formulario.'" filter="'.implode('&&', $filtro).'" hide="Submitted Login,Submitted From"]');. with the do_shortcode function included.

    Plugin Author Michael Simpson

    (@msimpson)

    I don’t know why that fails.

    See if it works using this code instead of “do_shortcode”

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/ExportToValue.php');
    $export = new ExportToValue();
    $atts = array(
            'function' => 'count',
            'limit' => "$offset,$limit",
            'filter' => implode('&&', $filtro),
            'hide' => 'Submitted Login,Submitted From'
    );
    $total = $export->export($formulario, $atts);

    Thread Starter Javier E.

    (@javier-e)

    Perfect! now it works with some lines edited:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/ExportToValue.php');
    							$export = new ExportToValue();
    							$atts = array(
    									'function' => 'count',
    									'no_echo' => true,
    									//'limit' => "$offset,$limit",
    									'filter' => implode('&&', $filtro)
    									//'hide' => 'Submitted Login,Submitted From'
    							);

    I replaced count functions inside ExportToValue.php

    case 'count':
                        $count = 0;
                        $colsPerRow = count($this->dataIterator->getDisplayColumns());
                        while ($this->dataIterator->nextRow()) {
                            $count += $colsPerRow;
                        }
                        if ($this->isFromShortCode) {
                            return $before . $count . $after;
                        }else if(isset($this->options['no_echo'])){
    						return $count;
    					}
                        else {
                            echo $before . $count . $after;
                            return;
                        }

    And of course the code for the table:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/ExportToHtmlTable.php');
    							$table = new ExportToHtmlTable();
    							$atts = array(
    									'function' => 'table',
    									'limit' => "$offset,$limit",
    									'filter' => implode('&&', $filtro),
    									'hide' => 'Submitted Login,Submitted From'
    							);
    							$table_html = $table->export($formulario, $atts);
    							echo $table_html;

    Thank you very much for your time!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcode on page templates submit time filter’ is closed to new replies.