New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File upload #40
Comments
I'm trying to get this working as well. Does the fact that this question is posted and has not been asnwered yet, mean that this is currently not possible?? Because that would be a big no-go for me... |
Well I actually wrote a custom filters and it was a bit of pain. In my case I was posting to the localhost of the same server so I used a plugin filter to make a temporary copy of the uploaded file, and then I added an extra POST argument with the location of the file. This only worked or me because my localhost website can pick up the file locally. I did try to attach it using POST but I had some trouble, but it may have been because I was using the wrong uploaded file location. The right one to use is This is my work-in-progress version:
|
Hi Dominic, Sound great! Unfortunately for me I'm using Gravity forms, so I will need to deep dive into this to be able to adapt your POST version as it seems you are using Contact Form 7. Why do you call this a work in progress version, which solution do you then currently use to accomplish this? Regards, |
Well I call it a 'work in progress' version because I would like to actually find a way to forward the uploaded files to the 3rd party site, even if it is on the same server. At the moment this code is working although I want to make it into a little plugin and fix it so it works as originally intended. At the moment it is just a workaround. Also, just so you know, in the code I posted I have used the prefix 'UPLOAD_'. This is because I have used this prefix for the name attribute on any upload file fields when I created my CF7 form. To adjust the code for Gravity Forms I would take some pieces from here: Cheers, |
Sorry I didn't have a chance to help you out more, but nice work @dominiceales. The hard part is extracting the file from the form submission, and as you've shown it's specific to each form plugin. You could also hook to Copying out the relevant GF stuff from the link above, in case it's not available:
I noticed you're using the Some alternatives I found for attaching:
|
@zaus I like the idea of using Would this be something you would consider adding to your plugin? If not would you recommend making a separate, dependent plugin or sending through a PR to this repo? |
@dominiceales good to know your "custom workaround" re: |
@zaus: I would love to have this functionality for my website, but don't have the knowledge to do it myself. Would you therefore be available to code this for me? Together with 2 or 3 smaller modifications to the standard version and the issue I'm currently having for getting this up-and-running (as just posted on Wordpress.com). And of course with the result as open source... If interested please let me know, so we can discuss this further! Regards, |
@zaus I have a working version of my extension plugin for CF7 (and probably Gravity forms too based on your code). There are two things I would need added to your plugin:
Requirement 1 above could be done with a plugin specific filter as you suggested but I think this would mean too much fiddling around for people using the plugin. I would prefer if the uploaded files were always included in the Let me know your thoughts on this. (I can post the plugin code if you like.) |
@zaus I thought I'd share a bit more. I have added my plugin here Here is the patch file for your repo so you can see what I have done to get it to work. diff --git a/forms-3rdparty-integration.php b/forms-3rdparty-integration.php
index 15dc9f4..ef3ef52 100644
--- a/forms-3rdparty-integration.php
+++ b/forms-3rdparty-integration.php
@@ -493,6 +493,7 @@ class Forms3rdPartyIntegration {
)
, $service
, $form
+ , $submission
);
//remote call
diff --git a/plugins/contactform7.php b/plugins/contactform7.php
index 68b00cf..4f42c88 100644
--- a/plugins/contactform7.php
+++ b/plugins/contactform7.php
@@ -77,7 +77,10 @@ class Forms3rdpartyIntegration_CF7 extends Forms3rdpartyIntegration_FPLUGIN {
*/
protected function GET_FORM_SUBMISSION($form) {
$submission = WPCF7_Submission::get_instance();
- if($submission) return $submission->get_posted_data();
+ if($submission) {
+ return $submission->get_posted_data()
+ + array('FILES'=>$submission->uploaded_files());
+ }
return array('no submission');
}
diff --git a/plugins/gravityforms.php b/plugins/gravityforms.php
index 9343d87..6a1e64c 100644
--- a/plugins/gravityforms.php
+++ b/plugins/gravityforms.php
@@ -74,7 +74,8 @@ class Forms3rdpartyIntegration_Gf extends Forms3rdpartyIntegration_FPLUGIN {
* Get the posted data from the form (or POST, wherever it is)
*/
protected function GET_FORM_SUBMISSION($form) {
- return stripslashes_deep($_POST); // fix issue #42
+ return stripslashes_deep($_POST) // fix issue #42
+ + array('FILES'=>$_FILES);
}
/** |
Rather than modifying plugin code to include the files (which is what I was trying to avoid) did you try a later hook to And instead of trying to roll support for all the Form Plugins, you can keep 'em separate (and as you mention Ninja needs to be separate anyway since it relies on paid stuff?). Something like the following should attach the files to the abstract class F3i_Files_Base {
function __construct() {
// expose files through submission $post array -- makes it available to mappings
add_filter(Forms3rdPartyIntegration::$instance->N('get_submission'), array(&$this, 'get_submission'), 11, 2);
// if you don't want user to need to actually type in the mapping
add_filter(Forms3rdPartyIntegration::$instance->N('service_filter_post'), array(&$this, 'automap'), 11, 5);
$this->_file_entry = 'FILES'; // or get from a configurable wp_option?
}
private $_file_entry; // alias to where we stick it in the submission/post array
public function get_submission($submission, $form) {
return $submission + array($this->_file_entry=>$this->get_files());
}
abstract protected function get_files();
public function automap($post, $service, $form, $sid, $submission) {
$post[$this->_file_entry] = $submission[$this->_file_entry];
}
}
/** plugin -- active if using GF **/
public class F3i_GF_Files : F3i_Files_Base {
protected function get_files() {
return $_FILES;
}
}
/** plugin -- active if using CF7 **/
public class F3i_CF7_Files : F3i_Files_Base {
protected function get_files() {
$cf7 = WPCF7_Submission::get_instance();
return $cf7 ? $cf7->uploaded_files() : array();
}
} Do you need the original submission in apply_filter for For that matter, you can do the above file inclusion directly on |
@zaus good points. I'll have a look at doing something like this. |
Closing, not to say this isn't a valid discussion but that it's not something for the core plugin. Please follow up here, I'm pretty sure I'll still get emails about it... |
Does it's working with Contact Form 7? Looks like everytime I fill the form the ConactForm7 delete all file into my server after sending by email. How to solve it? I found solution of commenting but after next Contact Form 7 update I need to comment it again? how to solve it? |
Hi there,
I am using CF7 with this plugin and it is great for posting to our backend jobs server.
I was wondering how I can get a file upload to be sent as well.
Any ideas?
Cheers,
Dominic
The text was updated successfully, but these errors were encountered: