Skip to content

Instantly share code, notes, and snippets.

@OutThisLife
Last active October 27, 2020 04:38
Show Gist options
  • Save OutThisLife/bd33674bae36121a3c99 to your computer and use it in GitHub Desktop.
Save OutThisLife/bd33674bae36121a3c99 to your computer and use it in GitHub Desktop.
Custom: Gravity Forms ajax submissions
<?php
/**
* Simple file to help add manual entries to a gravity form, so we don't have to deal w/ GFs output.
*/
require_once $_SERVER['DOCUMENT_ROOT'] . '/wp/wp-load.php';
$data = $_REQUEST;
// -----------------------------------------------
$form = GFAPI::get_form($data['form_id']);
# Build our entry
$entry = array();
$regex = '/^input_([0-9])_([0-9])$/';
foreach ($data AS $key => $value):
if (preg_match($regex, $key))
$key = preg_replace($regex, '$2', $key);
$entry[$key] = $value;
endforeach;
$entry['date_created'] = date('Y-m-d G:i');
$entry = GFAPI::add_entry($entry);
if (is_wp_error($entry)):
die(json_encode(array(
'error' => true,
'msg' => $entry->get_error_message(),
'form' => $form,
)));
else:
if (class_exists('GFMailChimp')):
$mc = new GFMailChimp;
$mc::export($entry, $form);
endif;
GFAPI::send_notifications($form, $entry, 'form_submission');
die(json_encode(array(
'error' => false,
'msg' => end($form['confirmations']),
'form' => $form,
)));
endif;
@tareqhi
Copy link

tareqhi commented Mar 24, 2016

Thanks for this code.
But I dont have any idea how to call this file on my JavaScript?
I have array as entry object variable in javascript file. I would like to send this variable to this file.
Can you plz provide me some hint?

@henrijeret
Copy link

For anybody looking for the aswer in the future. The hint is Wordpress' AJAX call for excecuting server side scripts and getting back answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment