Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/7045d925fdc8b1179480c84b83fb97a7 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/7045d925fdc8b1179480c84b83fb97a7 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Use upload file as notification condition
<?php
/**
* Plugin Name: [Forminator Pro] - Use upload file as notification condition
* Plugin URI: https://premium.wpmudev.org/
* Description: Use a hidden field to determine whether a file has been uploaded (as of 1.12.1.1)
* Author: Alessandro Kaounas @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: SLS-65
* License: GPLv2 or later
*/
add_action( 'forminator_custom_form_submit_before_set_fields', function( $entry, $form_id, $field_data_array ){
// User defined settings
$form = 10; // Define form to apply
$upload_field = 'upload-1'; // Set upload file field
$hidden_field = 'hidden-1'; // Set hidden input
if ( $form_id != $form ){
return $field_data_array;
}
$fields = wp_list_pluck( $field_data_array, 'name' );
$upload_field_key = array_search( $upload_field, $fields );
if( $upload_field_key && ! empty( $field_data_array[$upload_field_key]['value'] ) ){
add_filter( 'forminator_custom_form_mail_data', function( $data ) use ( $upload_field_key, $hidden_field ) {
$data[$hidden_field] = ( $upload_field_key ? 'has_file' : '' );
return $data;
});
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment