Plugin Directory

Changeset 1664390


Ignore:
Timestamp:
05/25/2017 12:04:25 AM (9 years ago)
Author:
toronetil
Message:

Added filter results by one word

Location:
select-options-from-database-for-contact-form-7/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • select-options-from-database-for-contact-form-7/trunk/readme.txt

    r1662710 r1664390  
    44Requires at least: 4.0
    55Tested up to: 4.2.2
    6 Stable tag: 1.0
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4646== Changelog ==
    4747
     48= 1.1 =
     49Added filter results by one word
     50
    4851= 1.0 =
    4952* First release.
  • select-options-from-database-for-contact-form-7/trunk/select_options_from_db_for_cf7.php

    r1423991 r1664390  
    55Plugin URI: https://wordpress.org/plugins/select-options-from-database-for-contact-form-7/
    66Description: Extend contact form 7 with new tag type : select options from database. Any column in your database can be a source to this select options element.
    7 Version: 1.0
    8 Author: toronetil
    9 Author URI: http://genie_platform.com/
     7Version: 1.1
     8Author: Dynamic Plugin
     9Author URI: http://dynamicplugin.com/
    1010License: GPL2
    1111*/
     
    8686    $type = $tag['type'];
    8787    $name = $tag['name'];
     88    $filter = $tag['filter'];
    8889    $options = (array) $tag['options'];
    8990    $values = (array) $tag['values'];
     
    101102    $columnNameShow='';
    102103    $columnNameValue='';
     104    $filter='';
    103105    $id_att = 'autocomplete';
    104106
     
    123125            $columnNameValue = $matches[1];
    124126        }
     127
     128        if ( preg_match( '%^filter:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
     129            $filter = $matches[1];
     130        }
    125131    }
    126132
     
    155161        $columnNameShowCorrect=str_replace($tableName."-","",$columnNameShow);
    156162        $columnNameValueCorrect=str_replace($tableName."-","",$columnNameValue);
    157         $query = "select ".$columnNameShowCorrect.",".$columnNameValueCorrect." from ".$tableName." group by ".$columnNameShowCorrect.",".$columnNameValueCorrect;
     163        if($filter!='')
     164        {
     165            $query = "select ".$columnNameShowCorrect.",".$columnNameValueCorrect." from ".$tableName." where
     166            ".$columnNameValueCorrect." like '%".Trim( $filter)."%'
     167              group by ".$columnNameShowCorrect.",".$columnNameValueCorrect;
     168        }
     169        else {
     170            $query = "select " . $columnNameShowCorrect . "," . $columnNameValueCorrect . " from " . $tableName . "
     171            group by " . $columnNameShowCorrect . "," . $columnNameValueCorrect;
     172        }
    158173        $optionValues = $db->getResults($query);
     174
    159175        foreach($optionValues as $optionValue)
    160176        {
     
    184200    $type = $tag['type'];
    185201    $name = $tag['name'];
     202    $filter = $tag['filter'];
    186203    $value = isset( $_POST[$name] ) ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) ) : '';
    187204
     
    204221    if (class_exists('WPCF7_TagGenerator')) {
    205222        $tag_generator = WPCF7_TagGenerator::get_instance();
    206         $tag_generator->add( 'dbactext', __( ' Select options from database  ', 'contact-form-7' ), 'wpcf7_tg_pane_dbactext' );
     223        $tag_generator->add( 'dbactext', __( ' Select options from database  ', 'contact-form-7' ),
     224            'wpcf7_tg_pane_dbactext' );
    207225    } else if (function_exists('wpcf7_add_tag_generator')) {
    208         wpcf7_add_tag_generator( 'dbactext', __( ' Select options from database ', 'wpcf7' ),   'wpcf7_tg_pane_dbactext', 'wpcf7_tg_pane_dbactext' );
     226        wpcf7_add_tag_generator( 'dbactext', __( ' Select options from database ', 'wpcf7' ),
     227            'wpcf7_tg_pane_dbactext', 'wpcf7_tg_pane_dbactext' );
    209228    }
    210229}
     
    228247                    <td>
    229248                        <fieldset>
    230                             <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
    231                             <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
     249                            <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?>
     250                            </legend>
     251                            <label><input type="checkbox" name="required" />
     252                                <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?>
     253                            </label>
    232254                        </fieldset>
    233255                    </td>
    234256                </tr>
    235257                <tr>
    236                     <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
    237                     <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
    238                 </tr>
    239                
    240                 <tr>
    241                     <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-tableName' ); ?>"><?php echo esc_html( __( 'Table Name', 'contact-form-7' ) ); ?></label></th>
    242                     <td><select name="tableNameSelected" class="tg-tableNameSelected oneline" id="<?php echo esc_attr( $args['content'] . '-tableNameSelected' ); ?>"
    243                     onchange="cpf7CopyValueAndFilter('<?php echo esc_attr( $args['content'] . '-tableNameSelected' ); ?>','<?php echo esc_attr( $args['content'] . '-tableName' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>')" />
     258                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>">
     259                            <?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
     260                    <td><input type="text" name="name" class="tg-name oneline"
     261                               id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
     262                </tr>
     263
     264                <tr>
     265                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-tableName' ); ?>">
     266                            <?php echo esc_html( __( 'Table Name', 'contact-form-7' ) ); ?></label></th>
     267                    <td><select name="tableNameSelected" class="tg-tableNameSelected oneline"
     268                                id="<?php echo esc_attr( $args['content'] . '-tableNameSelected' ); ?>"
     269                    onchange="cpf7CopyValueAndFilter('<?php echo esc_attr( $args['content'] . '-tableNameSelected' ); ?>',
     270                            '<?php echo esc_attr( $args['content'] . '-tableName' ); ?>',
     271                            '<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>',
     272                            '<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>',
     273                            '<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>',
     274                            '<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>')" />
    244275                    <?php
    245276                        foreach ($tables as $tableDetails)
    246277                        {
    247278                            ?>
    248                             <option value="<?php echo $tableDetails["TABLE_NAME"] ;?>" selected="selected" > <?php echo $tableDetails["TABLE_NAME"] ;?> </option>
     279                            <option value="<?php echo $tableDetails["TABLE_NAME"] ;?>"
     280                                    selected="selected" > <?php echo $tableDetails["TABLE_NAME"] ;?> </option>
    249281                            <?php
    250282                            }
    251283                           
    252284                    ?>
    253                     <td><input type="text"  name="tableName" class="tableNamevalue oneline option" id="<?php echo esc_attr( $args['content'] . '-tableName' ); ?>" style="visibility:hidden;" /></td>
     285                    <td><input type="text"  name="tableName" class="tableNamevalue oneline option" id="<?php echo
     286                        esc_attr( $args['content'] . '-tableName' ); ?>" style="visibility:hidden;" /></td>
    254287                    </select>
    255288                   
     
    258291               
    259292                <tr>
    260                     <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-columnNameShowName' ); ?>"><?php echo esc_html( __( 'Column name to show', 'contact-form-7' ) ); ?></label></th>
    261                     <td><select name="columnNameShowSelected" class="tg-columnNameShowSelected oneline" id="<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>"
    262                     onchange="cpf7CopyValue('<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>')" />
     293                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-columnNameShowName' ); ?>">
     294                            <?php echo esc_html( __( 'Column name to show', 'contact-form-7' ) ); ?></label></th>
     295                    <td><select name="columnNameShowSelected" class="tg-columnNameShowSelected oneline"
     296                                id="<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>"
     297                    onchange="cpf7CopyValue('<?php echo esc_attr( $args['content'] . '-columnNameShowSelected' ); ?>',
     298                            '<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>')" />
    263299                    <?php
    264300                        foreach ($columns as $columnDetails)
    265301                        {
    266302                            ?>
    267                             <option value="<?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?>" selected="selected" > <?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?> </option>
     303                            <option value="<?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?>"
     304                                    selected="selected" > <?php echo $columnDetails["TABLE_NAME"]."-".
     305                                    $columnDetails["COLUMN_NAME"];?> </option>
    268306                            <?php
    269307                            }
    270308                           
    271309                    ?>
    272                     <td><input type="text"  name="columnNameShow" class="columnNameShowvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>" style="visibility:hidden;" /></td>
     310                    <td><input type="text"  name="columnNameShow" class="columnNameShowvalue oneline option"
     311                               id="<?php echo esc_attr( $args['content'] . '-columnNameShow' ); ?>" style="visibility:hidden;" /></td>
    273312                    </select>
    274313                   
     
    277316               
    278317                <tr>
    279                     <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-columnNameValueName' ); ?>"><?php echo esc_html( __( 'Column name to value', 'contact-form-7' ) ); ?></label></th>
    280                     <td><select name="columnNameValueSelected" class="tg-columnNameValueSelected oneline" id="<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>"
    281                     onchange="cpf7CopyValue('<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>','<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>')" />
     318                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-columnNameValueName' ); ?>">
     319                            <?php echo esc_html( __( 'Column name to value', 'contact-form-7' ) ); ?></label></th>
     320                    <td><select name="columnNameValueSelected" class="tg-columnNameValueSelected oneline"
     321                                id="<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>"
     322                    onchange="cpf7CopyValue('<?php echo esc_attr( $args['content'] . '-columnNameValueSelected' ); ?>',
     323                            '<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>')" />
    282324                    <?php
    283325                        foreach ($columns as $columnDetails)
    284326                        {
    285327                            ?>
    286                             <option value="<?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?>" selected="selected" > <?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?> </option>
     328                            <option value="<?php echo $columnDetails["TABLE_NAME"]."-". $columnDetails["COLUMN_NAME"];?>"
     329                                    selected="selected" > <?php echo $columnDetails["TABLE_NAME"]."-".
     330                                    $columnDetails["COLUMN_NAME"];?> </option>
    287331                            <?php
    288332                            }
    289333                           
    290334                    ?>
    291                     <td><input type="text"  name="columnNameValue" class="columnNameValuevalue oneline option" id="<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>" style="visibility:hidden;" /></td>
     335                    <td><input type="text"  name="columnNameValue"
     336                               class="columnNameValuevalue oneline option"
     337                               id="<?php echo esc_attr( $args['content'] . '-columnNameValue' ); ?>"
     338                               style="visibility:hidden;" /></td>
    292339                    </select>
    293340                   
    294341                    </td>
    295342                </tr>
    296                
    297                 <tr>
    298                     <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class (optional)', 'contact-form-7' ) ); ?></label></th>
    299                     <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
     343                <tr>
     344                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-filter' ); ?>">
     345                            <?php echo esc_html( __( 'Filter', 'contact-form-7' ) ); ?></label></th>
     346                    <td><input type="text" name="filter" class="filtervalue oneline option"
     347                               id="<?php echo esc_attr( $args['content'] . '-filter' ); ?>" />
     348                        <br/>   <?php echo esc_html( __( 'One word only', 'contact-form-7' ) ); ?>
     349                    </td>
     350                </tr>
     351                <tr>
     352                    <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>">
     353                            <?php echo esc_html( __( 'Class (optional)', 'contact-form-7' ) ); ?></label></th>
     354                    <td><input type="text" name="class" class="classvalue oneline option"
     355                               id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
    300356                </tr>
    301357            </tbody>
     
    307363
    308364        <div class="submitbox">
    309             <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
     365            <input type="button" class="button button-primary insert-tag"
     366                   value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
    310367        </div>
    311368
    312369        <br class="clear" />
    313370
    314         <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
     371        <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>">
     372                <?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field,
     373                you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ),
     374                    '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden"
     375                                                                                  readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
    315376    </div>
    316377
Note: See TracChangeset for help on using the changeset viewer.