Checking for file upload pre-submission

Hi!

I’m trying to use the gform_pre_submission filter to set a field to 1 if a file has been uploaded but I’m not sure how to check if a file has been uploaded. This is what I currently have:

add_action('gform_pre_submission_96', function($form) {
    $file_upload_field_id = 80; 
    $hidden_field_id = 83;

	// Set field 83 1 if a file has been uploaded
	// set to 0 o.w. (this isn't strictly necessary since the default value is 0 but "just in case")
    if(!empty(rgpost('input_' . $file_upload_field_id))){
        $_POST['input_' . $hidden_field_id] = '1';
    }else{
		$_POST['input_' . $hidden_field_id] = '0';
	}
});

On submission, it enters the function but not the true part of the if statement. I’m thinking I need to check if a url exists but I’m not sure how to access it pre-submission. Multi-file upload is not enabled. Does anyone know what I should be using for the if statement?

Thanks!

File upload fields don’t use $_POST[ 'input_' . $file_upload_field_id ].

If you are using the default file upload field, which uses the browser upload input to accept a single file. The file details are located in $_FILES[ 'input_' . $file_upload_field_id ].

If you are using the multi-file enabled field, the arrays of file details can be accessed like so:

$files = rgars( GFFormsModel::$uploaded_files, '96/input_80', array() );
1 Like

Thank you! I knew it probably wasn’t right but I couldn’t find the correct way to check. It works perfectly now :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.