Changeset 2152238
- Timestamp:
- 09/06/2019 09:49:56 AM (7 years ago)
- Location:
- forms-3rd-party-inject-results/trunk
- Files:
-
- 1 deleted
- 2 edited
-
forms-3rdparty-inject-results.php (modified) (5 diffs)
-
readme.txt (modified) (5 diffs)
-
test-response.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
forms-3rd-party-inject-results/trunk/forms-3rdparty-inject-results.php
r1660575 r2152238 6 6 Description: Attach the results to the original submission 7 7 Author: zaus 8 Version: 0. 28 Version: 0.3 9 9 Author URI: http://drzaus.com 10 10 Changelog: 11 11 0.1 it begins 12 12 0.2 working version (at least, with GF) + readme 13 0.3 fix delimiter, removed testing endpoint 13 14 */ 14 15 … … 32 33 33 34 const FIELD = 'i2'; 35 const DELIM = '/'; 34 36 35 37 public function service_settings($eid, $P, $entity) { 36 $services = [];37 foreach(Forms3rdPartyIntegration::$instance->get_services() as $sid => $service) {38 // but NOT this one39 if($eid != $sid)40 $services []= array('id' => $sid, 'title' => isset($service['name']) ? $service['name'] : 'unknown-form');41 }42 38 ?> 43 39 <fieldset class="postbox"><legend class="hndle"><span><?php _e('Inject Results', $P); ?></span></legend> … … 47 43 <label for="<?php echo $field, '-', $eid ?>"><?php _e('Include which results?', $P); ?></label> 48 44 <textarea name="<?php echo $P, "[$eid][$field]"?>" class="text wide fat" id="<?php echo $field, '-', $eid ?>"><?php if(isset($entity[$field])) echo esc_html($entity[$field]) ?></textarea> 49 <em class="description"><?php echo sprintf(__('Enter the list of result values (given in url-nested form), one per line, to include in the response. Provide field aliases with %s', $P), '<code>response\\key=alias</code>'); ?></em>45 <em class="description"><?php echo sprintf(__('Enter the list of result values (given in url-nested form), one per line, to include in the response. Provide field aliases with %s', $P), "<code>response" . self::DELIM . "key=alias</code>"); ?></em> 50 46 </div> 51 47 </div> … … 104 100 foreach($reposts as $repost) { 105 101 106 // were we given an alias? 102 // were we given an alias? (optional) 107 103 $alias = explode('=', $repost); 108 104 $repost = reset($alias); 109 105 $alias = end($alias); 110 106 111 $keys = explode('/', $repost); 112 113 $resarg = $resultsArgs; 114 // only set if the desired (sub)key is present in the results 115 $isPresent = false; 116 // walk through nested keys 117 foreach($keys as $k) { 118 $isPresent = isset($resarg[$k]); 119 if(!$isPresent) break; 120 $resarg = $resarg[$k]; 121 } 122 if($isPresent) $extracted[$alias] = $resarg; 107 // only set if the desired key is present in the results 108 if(isset($resultsArgs[$repost])) { 109 $extracted[$alias] = $resultsArgs[$repost]; 110 } 123 111 } 124 112 … … 200 188 } 201 189 202 function flattenWithKeys(array $array, $childPrefix = '/', $root = '', $result = array()) {190 function flattenWithKeys(array $array, $childPrefix = self::DELIM, $root = '', $result = array()) { 203 191 // https://gist.github.com/kohnmd/11197713#gistcomment-1895523 204 192 -
forms-3rd-party-inject-results/trunk/readme.txt
r1660575 r2152238 4 4 Tags: contact form, form, CRM, mapping, 3rd-party service, services, remote request, forms-3rdparty, inject response, inject results 5 5 Requires at least: 3.0 6 Tested up to: 4.7.26 Tested up to: 5.2.2 7 7 Stable tag: trunk 8 8 License: GPLv2 or later … … 29 29 = How does it add the response values? = 30 30 31 Using the provided endpoint example [test-response.php](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php) will "echo" back your 3rdparty submission with keys altered to be prefixed with 'req-'. Soif your submission was31 If you have an endpoint [test-response.php](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php) that will "echo" back your 3rdparty submission with keys altered to be prefixed with 'req-', then if your submission was 32 32 33 33 { name: { first: "FirstName", last: "LastName" }, email: "myemail@email.com", etc: "foobar" } … … 35 35 The response would be flattened and prefixed to 36 36 37 { "req-name \first": "FirstName", "req-name\last": "LastName", "req-email": "myemail@email.com", "req-etc": "foobar" }37 { "req-name/first": "FirstName", "req-name/last": "LastName", "req-email": "myemail@email.com", "req-etc": "foobar" } 38 38 39 You would then inject `req-name\first` or `req-etc`. 40 41 To ensure that you're dynamically overwriting existing form submission values, you can use the test response endpoint with _value_ prefix/suffix like [test-response.php?prefix=1234&suffix=4321](http://yoursite.com/plugins/forms-3rdparty-inject-results/test-response.php?prefix=1234&suffix=4321), which would change the flattened response to 42 43 { "req-name\first": "1234FirstName4321", "req-name\last": "1234LastName4321", "req-email": "1234myemail@email.com4321", "req-etc": "1234foobar4321" } 39 You would then inject `req-name/first` or `req-etc`. 44 40 45 41 = What are some XML/JSON examples? = … … 70 66 == Changelog == 71 67 68 = 0.3 = 69 * fix: inconsistent nested key delimiters, now expecting '/' 70 * removed testing endpoint per WP Security request (see archives for example) 71 72 72 = 0.2 = 73 73 * confirmed with GF at least … … 79 79 == Upgrade Notice == 80 80 81 N/A. 81 = 0.3 = 82 Delimiter format handling has changed. May be a breaking change if you were using it "wrong" (according to how it was previously described).
Note: See TracChangeset
for help on using the changeset viewer.