Changeset 1946544
- Timestamp:
- 09/25/2018 06:27:34 AM (8 years ago)
- Location:
- gravity-pre-submission-confirmation/trunk
- Files:
-
- 3 edited
-
README.md (modified) (2 diffs)
-
gravity-pre-submission-confirmation.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gravity-pre-submission-confirmation/trunk/README.md
r1389068 r1946544 10 10 Requires at least: 3.5 11 11 12 Tested up to: 4. 512 Tested up to: 4.9.8 13 13 14 Stable tag: 1.0. 014 Stable tag: 1.0.2 15 15 16 License: GPLv 216 License: GPLv3 17 17 18 18 19 ## Synopsis19 ## Synopsis 20 20 21 21 This is an easy way to add a quick pre-submission confirmation page to your forms where users can preview their entered data before it is submitted. Gravity Forms does not provide any way to do this by default; however, with this plugin and a few simple form configuration instructions, you’ll have pre-submission confirmations working like magic! 22 22 23 ### Features23 ### Features 24 24 25 25 * Adds a quick pre-submission confirmation page to Gravity Forms. 26 26 * No configurations; Just Plugin & Play! 27 27 28 ## Installation28 ## Installation 29 29 1. Upload `GF-Confirmation` folder to your `/wp-content/plugins/` directory. 30 30 2. Activate the plugin from Admin > Plugins menu. … … 34 34 6. Update the Gravity form. 35 35 36 # Contribution36 # Contribution 37 37 38 38 Contributors are always welcome. 39 39 To contribute, just send a pull request. 40 40 41 # License42 This Plug-in is released under the same license as the WordPress software is released ie; the [GPLv 2](http://www.gnu.org/licenses/gpl-3.0.en.html) (or later) from the [Free Software Foundation](http://www.fsf.org/). A copy of the license is included with the Plug-in, but you can also read the text of the license [here](http://www.gnu.org/licenses/gpl-3.0.en.html).41 # License 42 This Plug-in is released under the same license as the WordPress software is released ie; the [GPLv3](http://www.gnu.org/licenses/gpl-3.0.en.html) (or later) from the [Free Software Foundation](http://www.fsf.org/). A copy of the license is included with the Plug-in, but you can also read the text of the license [here](http://www.gnu.org/licenses/gpl-3.0.en.html). 43 43 44 44 [https://github.com/patilswapnilv/gf-confirmation](https://github.com/patilswapnilv/gf-confirmation) -
gravity-pre-submission-confirmation/trunk/gravity-pre-submission-confirmation.php
r1449503 r1946544 4 4 Plugin URI: http://wordpress.org/plugins/gravity-pre-submission-confirmation/ 5 5 Description: Adds a quick pre-submission confirmation page to your Graviy forms where users can preview their entered data before it is submitted. 6 Version: 1.0. 16 Version: 1.0.2 7 7 Tags: gravity forms,confirmation, pre-submit, gravity forms extension, pre-submit confirmation 8 8 Author: patilswapnilv 9 9 Author URI: http://swapnilpatil.in/ 10 License: GPLv 210 License: GPLv3 11 11 Requires at least: 3.5 12 Tested up to: 4. 6 beta 113 Stable tag: 1.0. 112 Tested up to: 4.9.8 13 Stable tag: 1.0.2 14 14 */ 15 16 15 /* 17 18 16 This program is free software; you can redistribute it and/or modify 19 it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by17 it under the terms of the GNU General Public License (Version 4 - GPLv3) as published by 20 18 the Free Software Foundation. 21 22 19 This program is distributed in the hope that it will be useful, 23 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 24 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 22 GNU General Public License for more details. 26 27 23 You should have received a copy of the GNU General Public License 28 24 along with this program; if not, write to the Free Software 29 25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 26 */ 31 32 27 class GFPreviewConfirmation { 33 34 28 private static $lead; 35 36 29 public static function init() { 37 30 add_filter( 'gform_pre_render', array( __class__, 'replace_merge_tags' ) ); 38 31 } 39 40 32 public static function replace_merge_tags( $form ) { 41 42 33 $current_page = isset(GFFormDisplay::$submission[$form['id']]) ? GFFormDisplay::$submission[$form['id']]['page_number'] : 1; 43 34 $fields = array(); 44 45 35 // get all HTML fields on the current page 46 36 foreach($form['fields'] as &$field) { 47 48 37 // skip all fields on the first page 49 38 if(rgar($field, 'pageNumber') <= 1) 50 39 continue; 51 52 40 $default_value = rgar($field, 'defaultValue'); 53 41 preg_match_all('/{.+}/', $default_value, $matches, PREG_SET_ORDER); … … 60 48 } 61 49 } 62 63 50 // only run 'content' filter for fields on the current page 64 51 if(rgar($field, 'pageNumber') != $current_page) 65 52 continue; 66 67 53 $html_content = rgar($field, 'content'); 68 54 preg_match_all('/{.+}/', $html_content, $matches, PREG_SET_ORDER); … … 70 56 $field['content'] = self::preview_replace_variables($html_content, $form); 71 57 } 72 73 58 } 74 75 59 return $form; 76 60 } 77 78 61 /** 79 62 * Adds special support for file upload, post image and multi input merge tags. 80 63 */ 81 64 public static function preview_special_merge_tags($value, $input_id, $merge_tag, $field) { 82 83 65 // added to prevent overriding :noadmin filter (and other filters that remove fields) 84 66 if( ! $value ) 85 67 return $value; 86 87 68 $input_type = RGFormsModel::get_input_type($field); 88 89 69 $is_upload_field = in_array( $input_type, array('post_image', 'fileupload') ); 90 70 $is_multi_input = is_array( rgar($field, 'inputs') ); 91 71 $is_input = intval( $input_id ) != $input_id; 92 93 72 if( !$is_upload_field && !$is_multi_input ) 94 73 return $value; 95 96 74 // if is individual input of multi-input field, return just that input value 97 75 if( $is_input ) 98 76 return $value; 99 100 77 $form = RGFormsModel::get_form_meta($field['formId']); 101 78 $lead = self::create_lead($form); 102 79 $currency = GFCommon::get_currency(); 103 104 80 if(is_array(rgar($field, 'inputs'))) { 105 81 $value = RGFormsModel::get_lead_field_value($lead, $field); 106 82 return GFCommon::get_lead_field_display($field, $value, $currency); 107 83 } 108 109 84 switch($input_type) { 110 85 case 'fileupload': … … 117 92 break; 118 93 } 119 120 94 return $value; 121 95 } 122 123 96 public static function preview_image_value($input_name, $field, $form, $lead) { 124 125 97 $field_id = $field['id']; 126 98 $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name); 127 99 $source = RGFormsModel::get_upload_url($form['id']) . "/tmp/" . $file_info["temp_filename"]; 128 129 100 if(!$file_info) 130 101 return ''; 131 132 102 switch(RGFormsModel::get_input_type($field)){ 133 134 103 case "post_image": 135 104 list(,$image_title, $image_caption, $image_description) = explode("|:|", $lead[$field['id']]); 136 105 $value = !empty($source) ? $source . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : ""; 137 106 break; 138 139 107 case "fileupload" : 140 108 $value = $source; 141 109 break; 142 143 110 } 144 145 111 return $value; 146 112 } 147 148 113 public static function preview_image_display($field, $form, $value) { 149 150 114 // need to get the tmp $file_info to retrieve real uploaded filename, otherwise will display ugly tmp name 151 115 $input_name = "input_" . str_replace('.', '_', $field['id']); 152 116 $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name); 153 154 117 $file_path = $value; 155 118 if(!empty($file_path)){ … … 158 121 } 159 122 return $value; 160 161 123 } 162 163 124 /** 164 125 * Retrieves $lead object from class if it has already been created; otherwise creates a new $lead object. 165 126 */ 166 127 public static function create_lead( $form ) { 167 168 128 if( empty( self::$lead ) ) { 169 129 self::$lead = GFFormsModel::create_lead( $form ); 170 130 self::clear_field_value_cache( $form ); 171 131 } 172 173 132 return self::$lead; 174 133 } 175 176 134 public static function preview_replace_variables( $content, $form ) { 177 178 135 $lead = self::create_lead($form); 179 180 136 // add filter that will handle getting temporary URLs for file uploads and post image fields (removed below) 181 137 // beware, the RGFormsModel::create_lead() function also triggers the gform_merge_tag_filter at some point and will 182 138 // result in an infinite loop if not called first above 183 139 add_filter('gform_merge_tag_filter', array('GFPreviewConfirmation', 'preview_special_merge_tags'), 10, 4); 184 185 140 $content = GFCommon::replace_variables($content, $form, $lead, false, false, false); 186 187 141 // remove filter so this function is not applied after preview functionality is complete 188 142 remove_filter('gform_merge_tag_filter', array('GFPreviewConfirmation', 'preview_special_merge_tags')); 189 190 143 return $content; 191 144 } 192 193 145 public static function clear_field_value_cache( $form ) { 194 195 146 if( ! class_exists( 'GFCache' ) ) 196 147 return; 197 198 148 foreach( $form['fields'] as &$field ) { 199 149 if( GFFormsModel::get_input_type( $field ) == 'total' ) 200 150 GFCache::delete( 'GFFormsModel::get_lead_field_value__' . $field['id'] ); 201 151 } 202 203 152 } 204 205 153 } 206 207 154 GFPreviewConfirmation::init(); -
gravity-pre-submission-confirmation/trunk/readme.txt
r1449506 r1946544 1 === Gravity Pre-submission Confirmation===1 === Gravity Pre-submission Confirmation === 2 2 Contributors: patilswapnilv 3 3 Plugin Name: Gravity Pre-submission Confirmation 4 Plugin URI: https://wordpress.org/plugins/gravity-pre-submission-confirmation4 Plugin URI: https://github.com/patilswapnilv/Gravity-Pre-submission-Confirmation 5 5 Tags: gravity forms,confirmation, pre-submit, gravity forms extension, pre-submit confirmation 6 6 Author URI: http://swapnilpatil.in 7 7 Author: patilswapnilv 8 Version: 1.0. 08 Version: 1.0.2 9 9 Donate link: http://swapnilpatil.in/contribution 10 License: GPLv 2 or later11 License URI: http://www.gnu.org/licenses/gpl- 2.0.html10 License: GPLv3 11 License URI: http://www.gnu.org/licenses/gpl-3.0.en.html 12 12 Requires at least: 3.5 13 Tested up to: 4. 6 beat 114 Stable tag: 1.0. 113 Tested up to: 4.9.8 14 Stable tag: 1.0.2 15 15 16 16 … … 20 20 This is an easy way to add a quick pre-submission confirmation page to your forms where users can preview the information entered in the form before they submit it. Gravity Forms does not provide any way to do this by default; however, with this plugin and a few simple form configuration instructions, you’ll have pre-submission confirmations working like magic! 21 21 22 ### Features22 ### Features 23 23 24 24 * Adds a quick pre-submission confirmation page to Gravity Forms. … … 63 63 == Changelog == 64 64 65 = Version 1.0. 0=66 Initial Release.65 = Version 1.0.2 = 66 Tested for WordPress 4.9.8 67 67 68 68 = Version 1.0.1 = 69 69 Added support for PHP 7 and made translation ready. 70 71 = Version 1.0.0 = 72 Initial Release. 70 73 71 74
Note: See TracChangeset
for help on using the changeset viewer.