Skip to content

Commit

Permalink
Merge branch 'f-35' -- map by name issue #35
Browse files Browse the repository at this point in the history
  • Loading branch information
zaus committed Nov 19, 2015
2 parents b7b3760 + c24b33a commit b799328
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
3 changes: 2 additions & 1 deletion forms-3rdparty-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/zaus/forms-3rdparty-integration
Description: Send plugin Forms Submissions (Gravity, CF7, Ninja Forms, etc) to a 3rd-party URL
Author: zaus, atlanticbt, spkane
Version: 1.6.5.1
Version: 1.6.5.2
Author URI: http://drzaus.com
Changelog:
1.4 - forked from cf7-3rdparty. Removed 'hidden field plugin'.
Expand All @@ -25,6 +25,7 @@
1.6.4.2 - including original $submission in `service_filter_post` hook
1.6.4.3 - fix escape slashes in GF
1.6.5/.1 - github issue #43, indexed placeholder; added service to `get_submission` hook
1.6.5.2 - postbox open toggle, issue #35
*/

//declare to instantiate
Expand Down
12 changes: 7 additions & 5 deletions plugin-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
//prepare list of contact forms --
$forms = apply_filters($this->N('select_forms'), array());

$debugUrl = plugins_url('3rd-parties/service_test.php', __FILE__);

?>
<div id="<?php echo $P?>" class="wrap metabox-holder"><div id="poststuff">

Expand Down Expand Up @@ -66,7 +68,7 @@
<label for="dbg-debugmode"><?php _e('Debug Mode', $P); ?></label>
<input id="dbg-debugmode" type="checkbox" class="checkbox" name="<?php echo $P?>[debug][mode]" value="debug"<?php if(isset($debugOptions['mode']) ) echo ' checked="checked"'; ?> />
<em class="description"><?php _e('Send debugging information to indicated address, regardless of success or failure', $P)?>.</em>
<em class="description"><?php _e('Send service tests for full echo to:', $P); ?> <code><?php echo plugins_url('3rd-parties/service_test.php', __FILE__); ?></code></em>
<em class="description"><?php _e('Send service tests for full echo to:', $P); ?> <code><?php echo $debugUrl ?></code></em>
</div>
<div class="field">
<label for="dbg-sep">Separator</label>
Expand Down Expand Up @@ -100,7 +102,7 @@

<div class="description-body inside">

<fieldset><legend><span>Service</span></legend>
<fieldset class="postbox open"><legend class="hndle"><span>Service</span></legend>
<div class="inside">
<div class="field">
<label for="name-<?php echo $eid?>">Service Name</label>
Expand All @@ -109,8 +111,8 @@

<div class="field">
<label for="url-<?php echo $eid?>">Submission URL</label>
<input id="url-<?php echo $eid?>" type="text" class="text" name="<?php echo $P?>[<?php echo $eid?>][url]" value="<?php echo esc_attr($entity['url'])?>" />
<em class="description"><?php _e('The url of the external submission -- usually the <code>action</code> attribute of the 3rd-party form. See <a href="#dbg-debugmode">Debug Mode</a> setting for a working test url.', $P);?>.</em>
<input id="url-<?php echo $eid?>" type="text" class="text" name="<?php echo $P?>[<?php echo $eid?>][url]" value="<?php echo esc_attr(empty($entity['url']) ? $debugUrl : $entity['url'])?>" />
<em class="description"><?php echo sprintf(__('The url of the external submission -- usually the <code>action</code> attribute of the 3rd-party form. See <a href="%s">Debug Mode</a> setting for a <a href="%s">working test url</a>.', $P), '#dbg-debugmode', $debugUrl);?></em>
</div>


Expand Down Expand Up @@ -148,7 +150,7 @@
do_action($this->N('service_settings'), $eid, $P, $entity);
?>

<fieldset><legend><span>Mapping</span></legend>
<fieldset class="postbox open"><legend class="hndle"><span>Mapping</span></legend>
<table class="mappings inside">
<caption><?php _e('Listing of Form(s) Plugin fields to 3rd-party Mappings. <br />
* Note that the label is just for you to remind yourself what the mapping is for, and does not do anything. <br />
Expand Down
6 changes: 4 additions & 2 deletions plugin.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
var $postbox = $plugin.find('.postbox').not(function(i) { return i < 1 });

$postbox
.addClass('collapsed')
.each(function(i,o) {
$(o).find('.hndle').first()
var $me = $(o);
if(! $me.hasClass('open') ) $me.addClass('collapsed');

$me.find('.hndle').first()
.prepend('<span>[' + ($(o).data('icon') || '+') + ']</span> ')
.addClass('actn')
.data('actn', "toggle")
Expand Down
30 changes: 29 additions & 1 deletion plugins/gravityforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,35 @@ protected function IS_PLUGIN_FORM($form) {
* Get the posted data from the form (or POST, wherever it is)
*/
protected function GET_FORM_SUBMISSION($form) {
return stripslashes_deep($_POST); // fix issue #42
$submission = stripslashes_deep($_POST); // fix issue #42

### _log('gf-sub', $submission, $form['fields']);

// per issue #35 also include by name
foreach($submission as $id => $val) {
// find the field by id -- bonus, this handles checkbox 'input_4_3' -> '4'?
$fid = intval( str_replace('input_', '', $id) );
if($fid == 0) continue; // not a mappable input

$field = $this->findfield($form['fields'], $fid);

if($field !== false) {
if(isset($submission[ $field->label ]))
// preserve indexes
$submission[ $field->label ] = array_merge((array) $submission[ $field->label ], array($val));
else
$submission[ $field->label ] = $val;
}
}

return $submission;
}

private function findfield($fields, $fid) {
foreach($fields as $i => $field) {
if($field->id == $fid) return $field;
}
return false;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion plugins/ninjaforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ protected function IS_PLUGIN_FORM($form) {
*/
protected function GET_FORM_SUBMISSION($form) {
// interacting with user submission example -- http://ninjaforms.com/documentation/developer-api/actions/ninja_forms_process/
return $form->get_all_fields();
$submission = $form->get_all_fields();

// per issue #35 also include by name
foreach($submission as $id => $val) {
$field = $form->get_field_settings($id);
### _log('nja-fld ' . $id, $field);
$submission[ $field['data']['label'] ] = $val;
}

return $submission;
}

/**
Expand Down

0 comments on commit b799328

Please sign in to comment.