Changeset 1908528
- Timestamp:
- 07/13/2018 03:23:08 AM (8 years ago)
- Location:
- gravity-forms-extended-merge-tags/trunk
- Files:
-
- 3 edited
-
README.md (modified) (1 diff)
-
gravityforms-extended-merge-tags.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gravity-forms-extended-merge-tags/trunk/README.md
r1001499 r1908528 2 2 ================================ 3 3 4 Enables adding $_COOKIE, $_SERVER and $_SESSIONdata to a Gravity Form through merge tags4 Enables 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 3 3 Plugin Name: Gravity Forms Extended Merge Tags 4 4 Plugin URI: http://ericjuden.com/projects/wordpress/gravityforms-extended-merge-tags/ 5 Description: Enables adding $_COOKIE, $_SERVER and $_SESSIONdata to a Gravity Form through merge tags5 Description: Enables adding $_COOKIE, $_SERVER, $_SESSION, $_GET, $_POST and $_REQUEST data to a Gravity Form through merge tags 6 6 Author: ericjuden 7 7 Author URI: http://ericjuden.com 8 Version: 1. 08 Version: 1.1 9 9 */ 10 10 11 11 class 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); 15 15 } 16 16 17 function add_merge_tags( $form){17 function add_merge_tags( $form ) { 18 18 ?> 19 19 <script type="text/javascript"> 20 20 gform.addFilter("gform_merge_tags", "add_extended_tags"); 21 21 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 }); 22 38 mergeTags['custom'].tags.push({ 23 39 tag: '{COOKIE:key}', … … 40 56 } 41 57 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] ) ) { 51 68 $value = $_COOKIE[$key]; 52 $input = $this->build_hidden_field($input, $field, $value, $form_id);53 69 } else { 54 70 $value = ''; 55 71 } 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]; 66 77 } else { 67 78 $value = ''; 68 79 } 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]; 79 85 } else { 80 86 $value = ''; 81 87 } 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; 82 97 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 } 89 122 } 90 123 } else { … … 96 129 } 97 130 98 function build_hidden_field( $input, $field, $value, $form_id){131 function build_hidden_field( $input , $field , $value , $form_id ) { 99 132 $input = '<input name="input_'. $field['id'] .'" id="input_'. $form_id . '_' . $field['id'] .'" type="hidden" class="gform_hidden" value="'. $value .'" />'; 100 133 return $input; 101 134 } 102 135 103 function get_search_key( $text){136 function get_search_key( $text ) { 104 137 $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 ); 107 140 } else { 108 141 $key = false; … … 114 147 115 148 // Remove curly brace from end 116 $key = str_replace( '}', '', $key);149 $key = str_replace( '}', '' , $key ); 117 150 118 151 return $key; -
gravity-forms-extended-merge-tags/trunk/readme.txt
r1234397 r1908528 3 3 Tags: gravity, gravityforms, form, session, cookie, server 4 4 Requires at least: 3.7 5 Tested up to: 4. 35 Tested up to: 4.9.7 6 6 Stable tag: trunk 7 7 8 8 == Description == 9 This plugin allows you to use $_COOKIE, $_SERVER and $_SESSIONdata in a Gravity Form through the merge tags of a field. I’ve only really tested this using a hidden field.9 This 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. 10 10 11 11 == Screenshots == … … 26 26 27 27 == 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 28 32 = 1.0 = 29 33 * Initial release
Note: See TracChangeset
for help on using the changeset viewer.