Hi everyone,
My gravity form has a section where a user can upload a document, I’m trying to send that document off to my google drive or to a third party after the form gets submitted. I haven’t been able to do so, can anyone please let me know where I went wrong in my code below or if there’s something I’m missing? - Thank you
add_action( ‘gform_after_submission_182’, ‘post_to_third_party’, 10, 2 );
function post_to_third_party( $entry, $form )
{
$post_url = 'https://drive.google.com/drive/u/0/folders/160Jmd6Zj5oR-aC-y9hB ;
$body = array(
‘name’ => rgar( $entry, ‘11’),
‘file_upload’ => rgar( $entry, ‘13’)
);
$request = new WP_Http();
$response = $request->post($post_url, array(‘body’ => $body));
}
chrishajer
(Chris (Gravity Forms))
May 8, 2020, 9:31pm
2
Hi Nicholas. I recommend enabling logging on your site, and adding some custom logging statements to your code. Here is how you enable logging if you have not already:
For quite a while, enabling logging within Gravity Forms has been a go-to method for debugging any issues within Gravity Forms. As of Gravity Forms version 2.2, logging functionality has been moved from a separate add-on to becoming a core feature of...
Then, revise your code by adding some logging statements. I added some already, so you could use this code to see exactly what is going on:
add_action( 'gform_after_submission_182', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ){
GFCommon::log_debug( __METHOD__ . '(): My form => ' . print_r( $form, true ) );
GFCommon::log_debug( __METHOD__ . '(): My entry => ' . print_r( $entry, true ) );
$post_url = 'https://drive.google.com/drive/u/0/folders/160Jmd6Zj5oR-aC-y9hB;
$body = array(
'name' => rgar( $entry, '11'),
'file_upload' => rgar( $entry, '13')
);
$request = new WP_Http();
GFCommon::log_debug( __METHOD__ . '(): My request => ' . print_r( $request, true ) );
$response = $request->post($post_url, array('body' => $body));
GFCommon::log_debug( __METHOD__ . '(): My response => ' . print_r( $response, true ) );
}
Thank you much for your help @chrishajer , I will soon give this a try!
Hi @chrishajer - Thank you, enabling logging was helpful.
I’m trying to move the upload file from my gravity form submission to my inbox in MoveIT. I’m seeing a status code of 200 when looking at the logs but I’m not seeing my file being uploaded to my inbox in MoveIT. Please view my log below when you get the chance, do you have any idea of what I’m doing wrong or how I can implement this feature?
[status_code] => 200
[protocol_version] => 1.1
[success] => 1
[redirects] => 0
[url] => https://moveit.henrico.us/human.aspx?r=246971380&arg06=6114669&arg12=mailbox
[history] => Array
(
)
[cookies] => Requests_Cookie_Jar Object
(
[cookies:protected] => Array
(
[ASP.NET_SessionId] => Requests_Cookie Object
(
[name] => ASP.NET_SessionId
[value] => nure4o2mpncruhjm1ukubk2c
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[secure] => 1
[httponly] => 1
[samesite] => Lax
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[DMZCookieTest] => Requests_Cookie Object
(
[name] => DMZCookieTest
[value] => ifyoucanreadthisyourbrowsersupportscookies
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[siLockLongTermInstID] => Requests_Cookie Object
(
[name] => siLockLongTermInstID
[value] => 5845
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[expires] => 1652284697
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[MIDMZLang] => Requests_Cookie Object
(
[name] => MIDMZLang
[value] => en
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[expires] => 1652284697
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[JavascriptTest] => Requests_Cookie Object
(
[name] => JavascriptTest
[value] => 0
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[DesignModeTest] => Requests_Cookie Object
(
[name] => DesignModeTest
[value] => 0
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[NoWiz] => Requests_Cookie Object
(
[name] => NoWiz
[value] => 0
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[WizardVersions] => Requests_Cookie Object
(
[name] => WizardVersions
[value] => 3.1.5.0^3.1.5.0#4BD31B20-D5CB-45c6-94B5-EA50678F0A48#3.1.5|3.1.7.0#BAACAF97-A065-46f0-BB6F-C8EDD4C00761#3.1.7|3.2.0.0#CF71EA6C-6ABF-4bb7-B140-BBB26F9BD65D#3.2.0|3.3.0.0#CD72F011-CDD1-4c44-86D4-37E97CCED9BC#3.3.0|3.3.1.0#FB5FF2C3-B7EB-4394-804A-F5820554B59A#3.3.1|3.4.0.0#A81DF11E-14EB-48f6-B7CF-8D06AB608DE3#3.4.0|3.4.2.0#C5C02C87-534E-4bcd-A007-54975CF8BBAF#3.4.2|4.0.0.0#9D27C3FA-6662-4d29-99FB-A58A405FD584#4.0.0|4.5.0.0#03DED275-9DA6-450e-8A34-26684B2DDC78#4.5.0|5.0.0.0#02E58850-DBD8-40d9-8897-1F9F9471023C#5.0.0|5.1.0.0#DC811A54-8FE7-4653-9DB6-49CEABCE705A#5.1.0|5.5.0.0#0E409091-0585-415e-88B9-820BDC57094C#5.5.0|6.0.0.0#9C5FFF8F-0FE6-47ac-A0E6-85EF424F9D32#6.0.0|6.5.0.0#F589CCFE-5DCE-4009-844F-61433375F69B#6.5.0|7.0.0.0#B25AB9F1-B8A2-4072-8964-00C7EDF99750#7.0.0|7.1.0.0#CE335477-C2B3-4b59-8305-5D9A77D1F133#7.1.0|7.1.1.0#F88513AE-2CEB-4f9a-A863-CDC9913E3308#7.1.1|7.5.0.0#B2BF7972-1410-4501-8D5E-E42445D6D6E5#7.5.0|7.5.1.0#AFD262A2-9495-44de-B08A-D721B0D0D767#7.5.1|8.0.0.0#53A13770-347C-46e5-8C8E-54F514346BED#8.0.0|8.1.0.0#32E1ADD2-BE60-450e-9DF3-7CAAD1291A26#8.1.0|8.2.0.0#D5E8967C-C451-406e-AA2F-62DB81D47CF9#8.2.0|8.3.0.0#49B0CB30-31EB-4907-8312-4EA4B02DB4E1#8.3.0|9.0.0.0#72DBA6B5-BDCD-4622-959B-9C9BD959C764#9.0.0|9.5.0.0#58804433-7A99-4f6c-A95A-38D721B7E57D#9.5.0|9.6.0.0#5C6BA75D-7888-4F07-BAB1-080C59F88D11#9.6.0|10.0.0.0#7DF2666E-F78E-4905-8368-199D92FB014F#10.0.0|10.1.0.0#dcb786c7-4210-43d1-8944-55a2dcf9c3dc#10.1.0
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
[LongTermCookieExpireDate] => Requests_Cookie Object
(
[name] => LongTermCookieExpireDate
[value] => May 11 2022 11:58:17
[attributes] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[path] => /
[domain] => moveit.henrico.us
)
)
[flags] => Array
(
[creation] => 1589212697
[last-access] => 1589212697
[persistent] =>
[host-only] => 1
)
[reference_time] => 1589212697
)
)
)
)
[filename:protected] =>
[data] =>
[headers] =>
[status] =>
)
chrishajer
(Chris (Gravity Forms))
May 11, 2020, 7:31pm
5
Hi Nicholas. Can you share your modified code (so I can see what the logging lines should look like), and then share a link to the complete log file so we can see the whole thing in context? Thank you.
Thank you for helping me look into this @chrishajer , I appreciate your time.
Please see my modified code below, I couldn’t attach my log file in word format, can I email it to you by chance? I’m trying to upload the attached file of my gravity form submission to my inbox in MoveIT, please let me know if I’m doing this the wrong way or if you happen to have any suggestions/alternatives for me. Thanks again!
add_action( 'gform_after_submission_182', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form )
{
GFCommon::log_debug( __METHOD__ . '(): My form =' . print_r( $form, true ) );
GFCommon::log_debug( __METHOD__ . '(): My entry =' . print_r( $entry, true ) );
$post_url = 'https://moveit.henrico.us/human.aspx?r=246971380&arg06=611445669&arg12=mailbox';
$body = array(
'name' =rgar( $entry, '11'),
'upload' =rgar( $entry, '13')
);
$request = new WP_Http();
GFCommon::log_debug( __METHOD__ . '(): My request =' . print_r( $request, true ) );
$response = $request->post($post_url, array('body' =$body));
GFCommon::log_debug( __METHOD__ . '(): My response =' . print_r( $response, true ) );
}
chrishajer
(Chris (Gravity Forms))
May 11, 2020, 8:19pm
7
Sure, email me to link to the log file, or the log file in txt format, to chris@rocketgenius.com
Thanks
1 Like