Plugin Directory

Changeset 1908528


Ignore:
Timestamp:
07/13/2018 03:23:08 AM (8 years ago)
Author:
ericjuden
Message:

Updated to add support for $_GET, $_POST and $_REQUEST variables.

Location:
gravity-forms-extended-merge-tags/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gravity-forms-extended-merge-tags/trunk/README.md

    r1001499 r1908528  
    22================================
    33
    4 Enables adding $_COOKIE, $_SERVER and $_SESSION data to a Gravity Form through merge tags
     4Enables adding $_COOKIE, $_SERVER, $_SESSION, $_GET, $_POST and $_REQUEST data to a Gravity Form through merge tags
  • gravity-forms-extended-merge-tags/trunk/gravityforms-extended-merge-tags.php

    r1001499 r1908528  
    33Plugin Name: Gravity Forms Extended Merge Tags
    44Plugin URI: http://ericjuden.com/projects/wordpress/gravityforms-extended-merge-tags/
    5 Description: Enables adding $_COOKIE, $_SERVER and $_SESSION data to a Gravity Form through merge tags
     5Description: Enables adding $_COOKIE, $_SERVER, $_SESSION, $_GET, $_POST and $_REQUEST data to a Gravity Form through merge tags
    66Author: ericjuden
    77Author URI: http://ericjuden.com
    8 Version: 1.0
     8Version: 1.1
    99*/
    1010
    1111class GF_Extended_Merge_Tags {
    12     function __construct(){
    13         add_action('gform_admin_pre_render', array($this, 'add_merge_tags'));
    14         add_filter('gform_field_input', array($this, 'replace_merge_tags'), 10, 5);
     12    function __construct() {
     13        add_action( 'gform_admin_pre_render' , array( $this, 'add_merge_tags' ) );
     14        add_filter( 'gform_field_input' , array( $this , 'replace_merge_tags' ) , 10 , 5);
    1515    }
    1616   
    17     function add_merge_tags($form){
     17    function add_merge_tags( $form ) {
    1818?>
    1919        <script type="text/javascript">
    2020            gform.addFilter("gform_merge_tags", "add_extended_tags");
    2121            function add_extended_tags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
     22                mergeTags['custom'].tags.push({
     23                    tag: '{COOKIE:key}',
     24                    label: 'Cookie Data'
     25                });
     26                mergeTags['custom'].tags.push({
     27                    tag: '{GET:key}',
     28                    label: 'GET Data'
     29                });
     30                mergeTags['custom'].tags.push({
     31                    tag: '{POST:key}',
     32                    label: 'POST Data'
     33                });
     34                mergeTags['custom'].tags.push({
     35                    tag: '{REQUEST:key}',
     36                    label: 'REQUEST Data'
     37                });
    2238                mergeTags['custom'].tags.push({
    2339                    tag: '{COOKIE:key}',
     
    4056    }
    4157   
    42     function replace_merge_tags($input, $field, $value, $lead_id, $form_id){
    43         if(!is_admin()){    // Keep field the same while editing form. Only modify when actually displaying the form on the front-end.
    44             if(!is_array($value)){
    45                 switch($value){             
    46                     case (stristr($value, '{COOKIE:') !== FALSE):
    47                         $key = $this->get_search_key($value);
    48                        
    49                         if($key != ''){
    50                             if(isset($_COOKIE[$key])){
     58    function replace_merge_tags( $input , $field , $value , $lead_id , $form_id ) {
     59        if( !is_admin() ) { // Keep field the same while editing form. Only modify when actually displaying the form on the front-end.
     60            if( !is_array( $value ) ) {
     61                $key = $this->get_search_key( $value );
     62
     63                $did_process = true;
     64                if( $key != '' ) {
     65                    switch( $value ) {             
     66                        case ( stristr( $value, '{COOKIE:' ) !== FALSE ):
     67                            if( isset( $_COOKIE[$key] ) ) {
    5168                                $value = $_COOKIE[$key];
    52                                 $input = $this->build_hidden_field($input, $field, $value, $form_id);
    5369                            } else {
    5470                                $value = '';
    5571                            }
    56                         }
    57                         break;
    58                        
    59                     case (stristr($value, '{SERVER:') !== FALSE):
    60                         $key = $this->get_search_key($value);
    61                        
    62                         if($key != ''){
    63                             if(isset($_SERVER[$key])){
    64                                 $value = $_SERVER[$key];
    65                                 $input = $this->build_hidden_field($input, $field, $value, $form_id);
     72                            break;
     73
     74                        case ( stristr( $value, '{GET:' ) !== FALSE ):
     75                            if( isset( $_GET[$key] ) ) {
     76                                $value = $_GET[$key];
    6677                            } else {
    6778                                $value = '';
    6879                            }
    69                         }
    70                         break;
    71                        
    72                     case (stristr($value, '{SESSION:') !== FALSE):
    73                         $key = $this->get_search_key($value);
    74                        
    75                         if($key != ''){
    76                             if(isset($_SESSION[$key])){
    77                                 $value = $_SESSION[$key];
    78                                 $input = $this->build_hidden_field($input, $field, $value, $form_id);
     80                            break;
     81
     82                        case ( stristr( $value, '{POST:' ) !== FALSE ):
     83                            if( isset( $_POST[$key] ) ) {
     84                                $value = $_POST[$key];
    7985                            } else {
    8086                                $value = '';
    8187                            }
     88                            break;
     89
     90                        case ( stristr( $value, '{REQUEST:' ) !== FALSE ):
     91                            if( isset( $_REQUEST[$key] ) ) {
     92                                $value = $_REQUEST[$key];
     93                            } else {
     94                                $value = '';
     95                            }
     96                            break;
    8297                           
    83                         }
    84                         break;
    85                        
    86                     default:
    87                        
    88                         break;
     98                        case ( stristr( $value, '{SERVER:' ) !== FALSE ):
     99                            if( isset( $_SERVER[$key] ) ) {
     100                                $value = $_SERVER[$key];
     101                            } else {
     102                                $value = '';
     103                            }
     104                            break;
     105                           
     106                        case ( stristr( $value, '{SESSION:' ) !== FALSE ):
     107                            if( isset( $_SESSION[$key] ) ) {
     108                                $value = $_SESSION[$key];
     109                            } else {
     110                                $value = '';
     111                            }
     112                            break;
     113                           
     114                        default:
     115                            $did_process = false;
     116                            break;
     117                    }
     118
     119                    if( $value != '' && $did_process ){
     120                        $input = $this->build_hidden_field( $input , $field , $value , $form_id );
     121                    }
    89122                }
    90123            } else {
     
    96129    }
    97130   
    98     function build_hidden_field($input, $field, $value, $form_id){
     131    function build_hidden_field( $input , $field , $value , $form_id ) {
    99132        $input = '<input name="input_'. $field['id'] .'" id="input_'. $form_id . '_' . $field['id'] .'" type="hidden" class="gform_hidden" value="'. $value .'" />';
    100133        return $input;
    101134    }
    102135   
    103     function get_search_key($text){
     136    function get_search_key( $text ) {
    104137        $key = '';
    105         if(!is_array($text)){
    106             $key = substr($text, strpos($text, ':')+1);         
     138        if( !is_array( $text ) ) {
     139            $key = substr( $text , strpos( $text , ':' ) + 1 );         
    107140        } else {
    108141            $key = false;
     
    114147       
    115148        // Remove curly brace from end
    116         $key = str_replace('}', '', $key);
     149        $key = str_replace( '}', '' , $key );
    117150       
    118151        return $key;
  • gravity-forms-extended-merge-tags/trunk/readme.txt

    r1234397 r1908528  
    33Tags: gravity, gravityforms, form, session, cookie, server
    44Requires at least: 3.7
    5 Tested up to: 4.3
     5Tested up to: 4.9.7
    66Stable tag: trunk
    77
    88== Description ==
    9 This plugin allows you to use $_COOKIE, $_SERVER and $_SESSION data in a Gravity Form through the merge tags of a field. I’ve only really tested this using a hidden field.
     9This plugin allows you to use $_COOKIE, $_SERVER, $_SESSION, $_GET, $_POST and $_REQUEST data in a Gravity Form through the merge tags of a field. I’ve only really tested this using a hidden field.
    1010
    1111== Screenshots ==
     
    2626
    2727== Changelog ==
     28= 1.1 =
     29* Added support for $_GET, $_POST and $_REQUEST variables
     30* Cleaned up the code to better adhere to WordPress coding standards
     31
    2832= 1.0 =
    2933* Initial release
Note: See TracChangeset for help on using the changeset viewer.