diff --git a/gravityforms-multiple-form-instances.php b/gravityforms-multiple-form-instances.php
index c8babb1..239a02a 100644
--- a/gravityforms-multiple-form-instances.php
+++ b/gravityforms-multiple-form-instances.php
@@ -26,6 +26,8 @@ class Gravity_Forms_Multiple_Form_Instances {
public function __construct() {
// hook the HTML ID string find & replace functionality
add_filter( 'gform_get_form_filter', array( $this, 'gform_get_form_filter' ), 10, 2 );
+ // hook the multifile upload script replace functionality
+ add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
@@ -95,6 +97,14 @@ public function gform_get_form_filter( $form_string, $form ) {
'GFCalc(' . $form['id'] . ',' => 'GFCalc(' . $random_id . ',',
'gf_global["number_formats"][' . $form['id'] . ']' => 'gf_global["number_formats"][' . $random_id . ']',
'gform_next_button_' . $form['id'] . '_' => 'gform_next_button_' . $random_id . '_',
+ 'multipart_params":{"form_id":' . $form['id'] . ',' => 'multipart_params":{"form_id":' . $random_id . ',"original_id":' . $form['id'] . ',"random_id":' . $random_id . ',',
+ 'gform_multifile_upload_' . $form['id'] . '_' => 'gform_multifile_upload_' . $random_id . '_',
+ 'gform_drag_drop_area_' . $form['id'] . '_' => 'gform_drag_drop_area_' . $random_id . '_',
+ 'gform_browse_button_' . $form['id'] . '_' => 'gform_browse_button_' . $random_id . '_',
+ 'gform_preview_' . $form['id'] . '_' => 'gform_preview_' . $random_id . '_',
+ 'gform_multifile_messages_' . $form['id'] . '_' => 'gform_multifile_messages_' . $random_id . '_',
+ 'gform_uploaded_files_' . $form['id'] => 'gform_uploaded_files_' . $random_id,
+ 'gformDeleteUploadedFile(' . $form['id'] . ',' => 'gformDeleteUploadedFile(' . $random_id . ',',
$hidden_field => "" . $hidden_field,
);
@@ -109,6 +119,17 @@ public function gform_get_form_filter( $form_string, $form ) {
return $form_string;
}
+ /**
+ * Enqueues the multifile upload script in wordpress scripts.
+ *
+ * @access public
+ *
+ * @return void
+ */
+ public function enqueue_scripts() {
+ wp_enqueue_script( 'gform_mfi_multifile', plugin_dir_url( __FILE__ ) . 'js/gravityforms-mfi-multifile.js', array( 'jquery', 'gform_gravityforms' ) );
+ }
+
}
// initialize the plugin
diff --git a/js/gravityforms-mfi-multifile.js b/js/gravityforms-mfi-multifile.js
new file mode 100644
index 0000000..ecfd684
--- /dev/null
+++ b/js/gravityforms-mfi-multifile.js
@@ -0,0 +1,32 @@
+//----------------------------------------
+//------ MULTIFILE UPLOAD FUNCTIONS ------
+//----------------------------------------
+
+(function (gform, gfMultiFileUploader, $) {
+ $(document).bind('gform_post_render', function(e, formID){
+ $("form#gform_" + formID + " .gform_fileupload_multifile").each(function(){
+ var settings = $(this).data('settings');
+ var uploader = gfMultiFileUploader.uploaders[settings.container];
+ uploader.bind('BeforeUpload', function(up, file) {
+ uploader.settings.multipart_params.form_id = uploader.settings.multipart_params.original_id;
+ });
+ });
+ });
+
+ gform.addFilter('gform_file_upload_markup', function(html, file, up, strings, imagesUrl){
+ var html = '' + file.name + '';
+ var formId = up.settings.multipart_params.random_id;
+ var fieldId = up.settings.multipart_params.field_id;
+ html = "
"
+ + html;
+ return html;
+ });
+
+}(window.gform = window.gform || {}, window.gfMultiFileUploader = window.gfMultiFileUploader || {}, jQuery));
diff --git a/tests/unit-tests/GFMFI_GformGetFormFilterTest.php b/tests/unit-tests/GFMFI_GformGetFormFilterTest.php
index e382454..04ff473 100644
--- a/tests/unit-tests/GFMFI_GformGetFormFilterTest.php
+++ b/tests/unit-tests/GFMFI_GformGetFormFilterTest.php
@@ -494,6 +494,94 @@ public function testGformNextButtonReplacement() {
$this->assertSame( $expected, $actual );
}
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testMultipartParamsAddition() {
+ $input = 'multipart_params":{"form_id":' . $this->form['id'] . ',';
+ $expected = 'multipart_params":{"form_id":' . $this->randomId . ',"original_id":' . $this->form['id'] . ',"random_id":' . $this->randomId . ',';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformMultifileUploadReplacement() {
+ $input = 'gform_multifile_upload_' . $this->form['id'] . '_';
+ $expected = 'gform_multifile_upload_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformDragDropAreaReplacement() {
+ $input = 'gform_drag_drop_area_' . $this->form['id'] . '_';
+ $expected = 'gform_drag_drop_area_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformBrowseButtonReplacement() {
+ $input = 'gform_browse_button_' . $this->form['id'] . '_';
+ $expected = 'gform_browse_button_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformPreviewReplacement() {
+ $input = 'gform_preview_' . $this->form['id'] . '_';
+ $expected = 'gform_preview_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformMultifileMessagesReplacement() {
+ $input = 'gform_multifile_messages_' . $this->form['id'] . '_';
+ $expected = 'gform_multifile_messages_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformUploadedFilesReplacement() {
+ $input = 'gform_uploaded_files_' . $this->form['id'] . '_';
+ $expected = 'gform_uploaded_files_' . $this->randomId . '_';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
+ */
+ public function testGformDeleteUploadedFileReplacement() {
+ $input = 'gformDeleteUploadedFile(' . $this->form['id'] . ',';
+ $expected = 'gformDeleteUploadedFile(' . $this->randomId . ',';
+ $actual = $this->gfmfi->gform_get_form_filter( $input, $this->form );
+
+ $this->assertSame( $expected, $actual );
+ }
+
/**
* @covers Gravity_Forms_Multiple_Form_Instances::gform_get_form_filter
*/