Is there a way to get file in the hook gform_pre_submission() [RESOLVED]

Hey there,

I am calling API to submit the data of my form.
To display the correct confirmation message if a call of API fail, I need to put my code into gform_pre_submission() hook, to be able to tell the user that the submition to my API fail or another message. (I do that in gform_confirmation() )

The issue I have is that into gform_pre_submission() I cant acces the file upload field. All other field work great with rgpost( “input_1” )

I tried :
rgpost( ‘input_1’ )
$entry[ ‘1’ ]

Nothing return me the actual file.

My code work in the gform_after_submission. But, If I do that in this hook, I cant display a custom message if a call fail…

I cant send here all my code cause its really large and contain personal data but you can just take this as example :

add_action( 'gform_pre_submission_2', 'after_submission_parrainage', 10, 2 );
function after_submission_parrainage($entry, $form)
	 GFCommon::log_error( (' $$$ '));
	 GFCommon::log_error( (rgpost( 'input_1' )));
	 GFCommon::log_error( (rgpost( 'input_27' )));
	 GFCommon::log_error( ($entry[ '28' ]));
	 GFCommon::log_error( ($_POST['input_27']));
	 GFCommon::log_error( (' $$$ '));

This return 0 data in the gform_pre_submission(), but return correct things in the gform_after_submission

PS : I already tried this : Read form data at gform_pre_submission

	 GFCommon::log_debug( __METHOD__ . '(): The POST => ' . print_r( $_POST, true ) );

It return me everything except the files.

Try using gform_field_validation instead.

Dont know if I can use that, can my API call is fired in gform_after_submission (cause pre_submission doesnt have the files).

I think gform_field_validation strike before gform_after_submission … So I cant know if my API call failed or not.

Will dig into it today If I found a solution I will post it here.

EDIT : In fact gform_field_validation is execute on every page of my form, this is not possible for me cause my API call need to be strike when the field is submited.

Just need to find the right hook to submit the form, call my API and display the good confirmation message right after

Also tryied to use this hook : gform_post_process - Gravity Forms Documentation

Same issue, I got all the field but not the 2 files.

Depending on how your API expects the file to be submitted (and response provided), the Gravity Flow outgoing webhook may be something you want to look at. It has hooked into filters that you could effectively think of it as running after gform_after_submission, with the ability to map response values into fields (without code) which display in confirmation or drive conditional logic.

For example, if your API needs the file mime-encoded, the example #7 from gravityflow_webhook_args shows how to mime encode the file.

If you’ve got more targeted questions related to the API formatting, please send us a support ticket and happy to help further.


Thanks for your answer, as a developper I was not really agree to use another API call, I allready use 3 different API, to put data into my CRM, upload file on office365 and auto complete the form.

What worked is to do all my API call in this hook :

after I use gform_confirmation()

With a global PHP variable, I pass if there is any error in my api call, and so, im able to display different message.

Idk why it took that much time to find out all the hook and stuff, but any it work now…

Just a quick message that gform_entry_pre_handle_confirmation doesn’t support the form ID after the name of the function like gform_entry_pre_handle_confirmation_2 (for form ID number 2)

All my other code work well like gform_confirmation_2 or gform_validation_2

So what I did is that i’ve added an if in the filter:

add_action( ‘gform_entry_pre_handle_confirmation’, ‘apres_submit_preinscription’, 10, 2 );
function apres_submit_preinscription( $entry, $form )
if ($form[‘id’] == 2)

So my code is only executed on the form with ID 2. But its strange that it doesnt support the “_2” like any other filter from the plugin.

Pretty sure its a bug from the core code itself :slight_smile:

It’s not a bug - not all filters have a form-specific version where you can add the form ID to the filter or hook name. Your workaround is the proper way to check the form ID when there is no form-specific version of the hook. Thank you.