Integrating Gravity Forms with a 3rd Party (Eloqua) - forms

I wondering if you guys could help. I am trying to integrate Gravity forms with Eloqua CRM. I've tried both '3rd Party Integration' plugin and I have also tried adding the gf after submission function in my functions.php file. However, I have not been able to get this to work. My code is below. I entered the url of my form in 'eloqua' (https://s1913652004.t.eloqua.com/e/f2) There is also a form id, but I don't see anywhere to put that.
add_action( 'gform_after_submission_1', 'post_to_third_party', 10, 2 ); function post_to_third_party( $entry, $form ) {
$post_url = 'https://s1913652004.t.eloqua.com/e/f2';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'email' => rgar( $entry, '2' ),
'country' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_after_submission_1: body => ' . print_r( $body, true ) );
$request = new WP_Http();`enter code here`
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission_1: response => ' . print_r( $response, true ) );

Use the Gravity Forms Eloqua Add-On. It's actively maintained.

Related

Gravityview - Show payment status of another form

I currently have Gravityview view which is getting the source from form A. However, I want to show if the current user has made a payment on form B. Obviously this can be fetched from the {payment_status} merge tag of form B. But How can I pull the data of form B onto the Gravity view custom content field of form A?
I've looked at the gform_entry_id_pre_save_lead hook but I think there's a better way. Thanks for your help in advance..
add_filter( 'gform_entry_id_pre_save_lead', 'my_update_entry_on_form_submission', 10, 2 );
function my_update_entry_on_form_submission( $entry_id, $form ) {
$update_entry_id = rgpost( 'my_update_entry_id' );
return $update_entry_id ? $update_entry_id : $entry_id;
}
You can either use the Gravityview Multiple Forms Add-on or you can try adding the following code to your functions.php:
function gf_check_form($atts = array()) {
$details = shortcode_atts( array(
'form_id' => "",
'user' => ""
), $atts );
$form_id = $details['form_id'];
$search_criteria = array(
'status' => 'active',
'field_filters' => array(
'mode' => 'all',
array(
'key' => 'created_by',
'operator'=> 'is',
'value' => $details['user']
)
)
);
$entries = GFAPI::get_entries( $form_id, $search_criteria);
foreach($entries as $entry){
$paid .= 'Paid on '.date("F d, Y", strtotime($entry['date_created'])).'<br><br>';
}
return $paid;
}
add_shortcode( 'check_form', 'gf_check_form' );
You can then add the following shortcode to your Gravityview in a custom content field:
[check_form form_id="Add the form ID of form B here" user="{created_by:ID}"]

Gravity form gform_after_submission is not working

I am trying to submit the form data to a third party on successful submission of gravity form. But I am stuck at the first stage. Looks like the function is not running or may be something wrong with my code. Here is my code:
add_action( 'gform_after_submission_8', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$body = array(
'name' => rgar( $entry, '1' ),
'email' => rgar( $entry, '2' ),
'phone' => rgar( $entry, '3' ),
'case_details' => rgar( $entry, '4' ),
);
print_r($body);
}
Any help will be appreciated. Thanks in advance.

How to receive REMOTE POST response data and print to Gravity Forms confirmation page

I'm struggling with getting remote post response data to print on the Gravity Forms confirmation page. The data from the form is posted to the 3rd party site successfully and my logs show that the response data is received, however the received data is not printing to the confirmation page.
I have tried many variations such as;
$request = new WP_Http();
$data = json_decode( wp_remote_retrieve_body( $response ) );
$response = wp_remote_post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );
return $confirmation;
I submit the data via a plugin and have tried with the filters gform_confirmation, gform_after_submission, and gform_entry_post_save to no avail.
After many support tickets to Gravity Forms; I'm told that to do this requires additional scripting.
Thank you,
Richard
This is the code I have so far for the plugin.
add_filter( 'gform_confirmation_2', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$post_url = 'my_post_url';
$body = array(
'VTC_ID' => rgar( $entry, '15' ),
'Member_ID' => rgar( $entry, '16' ),
'bname' => rgar( $entry, '3' ),
'baddress' => rgar( $entry, '4' ),
'bcity' => rgar( $entry, '5' ),
'bstate' => rgar( $entry, '6' ),
'bcountry' => rgar( $entry, '7' ),
'bzip' => rgar( $entry, '8' ),
'phone' => rgar( $entry, '9' ),
'email' => rgar( $entry, '17' ),
'password' => rgar( $entry, '11' ),
'isTrial' => rgar( $entry, '12' ),
'isActive' => rgar( $entry, '18' ),
'trialStart' => rgar( $entry, '13' ),
'trialEnd' => rgar( $entry, '14' ),
);
GFCommon::log_debug( 'gform_confirmation: body => ' . print_r( $body, true ) );
$request = new WP_Http();
$response = wp_remote_post( $post_url, $parameters );
$confirmation .= print_r( $response, true );
return $confirmation;
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );
}
Assuming everything is part of the same submission process, you should be able to use the gform_confirmation hook instead of the gform_after_submission.
add_filter( 'gform_confirmation_123', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_post( $post_url, $parameters );
$confirmation .= print_r( $response, true );
return $confirmation;
}
This assumes that:
Your confirmation is configured for text (not page or redirect)
You will need to:
Update the "123" in the filter name to your form ID
Update the wp_remote_post() to actually use the variables applicable to your request
Update the $confirmation to include the actual content from the response that you want
Starting with #dave-from-gravity-wiz answer, I used GET not POST with github API for simplicity when experimenting
add_filter( 'gform_confirmation_4', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_get( 'https://api.github.com/users/someuser' );
if ( is_wp_error( $response ) ) {
echo 'An error happened';
} else {
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
}
$confirmation .= print_r( $data->id, true );
return $confirmation;
}
This takes the json table you can see on the url and only prints the 'id' number in the response on the form submission confirmation, or any key label you change it to. If you want to show more than one value I was told you can concatenate the print_r so this works in the above example:
$confirmation .= print_r( $data->id, true )." <br/> ".print_r($data->login, true);
return $confirmation;

sending form values $form_state['redirect'] Form API Drupal

I want to send my form values using form API drupal. I have following value
$form['billing']["cardholders_name"] = array(
'#type' => 'textfield',
'#title' => t("Cardholder's Name"),
'#required' => TRUE,
'#prefix' => '<div class="field-wrapper-w1 card-name">'
);
I am writing following code in my form submit function
function test_form_submit($form, &$form_state) {
$form_state['redirect'] = 'www.test.com/page' . '?cname=' . $form_state['values']['billing[cardholders_name]'];
}
But it seems like it is not working. Please help
The following example appears in
http://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_redirect_form/7
$form_state['redirect'] = array(
'node/123',
array(
'query' => array(
'foo' => 'bar',
),
'fragment' => 'baz',
),
);
Any value for form element will be in $form_state under values so in your function test_form_submit you can access cardholders_name
$form_state['values']['cardholders_name']
also you can do it in this way using drupal_goto()
drupal_goto('www.test.com/page' . '?cname=' . $form_state['values']['cardholders_name]);

Are there any examples using the Zend/Code/Generator component

I use Symfony's console component together with the Zend_CodeGenerator component. There was very few examples but I got it work -- http://framework.zend.com/manual/1.12/en/zend.codegenerator.html. Of course it didn't handle namespaces and use statements. Today I figured I try Zend/Code/Generator. I found an old post here http://mwop.net/blog/261-Code-Generation-with-ZendCodeGenerator.html.
So using Composer I installed the component and went about updated my code (see below). I'm having issues with doc blocks not being generated (see new version). There's no resulting errors indicating the parameters are wrong just no docblocks. I quickly reviewed the source code, api and even some the unit tests. So before I give up on this and stick with ZF1 CodeGenerator I wondered if there are any examples out there using docblocks.
Old Version
<?php
$class = new Zend_CodeGenerator_Php_Class();
$docblock = new Zend_CodeGenerator_Php_Docblock(array(
'shortDescription' => 'Index controller',
'tags' => array(
array(
'name' => 'category',
'description' => 'Controller',
),
array(
'name' => 'package',
'description' => 'Application\Controller',
),
),
));
$methods = array(
array(
'name' => 'indexAction',
'docblock' => new Zend_CodeGenerator_Php_Docblock(array(
'shortDescription' => 'Index action',
'tags' => array(
new Zend_CodeGenerator_Php_Docblock_Tag_Return(array(
'datatype' => 'void',
)),
),
)),
),
);
$class->setName("Admin_IndexController")
// Additional step needed to add namespace and use statement
->setExtendedClass('Action')
->setDocblock($docblock)
->setMethods($methods);
$file = new Zend_CodeGenerator_Php_File(array(
'classes' => array($class),
));
$code = $file->generate();
// Remove all that extra blank lines
$code = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $code);
if (file_put_contents('application/modules/admin/controllers/IndexController.php', $code)) {
$this->output->writeln(
'Controller generated ' . realpath('application/modules/admin/controllers/IndexController.php')
);
}
New Version
<?php
$classGenerator = new ClassGenerator();
$classGenerator->setName('Admin_IndexController')
->setExtendedClass('Action')
->setDocBlock(
new DocBlockGenerator(
'Index controller',
'',
array(
new Tag(
array(
'name' => 'category',
'description' => 'Controller'
)
),
new Tag(
array(
'name' => 'package',
'description' => 'Application\Controller'
)
)
)
)
)
->addMethods(
array(
new MethodGenerator(
'indexAction',
array(),
null,
null,
new DocBlockGenerator(
'Index action'
)
)
)
);
$fileGenerator = new FileGenerator();
$fileGenerator->setUse('Application\Controller\Action')
->setClass($classGenerator);
$code = $fileGenerator->generate();
// ...