| Post |
|
Guest
| Simon 1:36 pm January 23, 2012
| |
|
|
Hi everyone,
I've had an issue with the upload function on multiforms for a while, and it causes confusion for people submitting. Thought it was about time I asked for help/advice.
I have a two-part multi-form. Form 1 has an upload field (required), Form 2 does not.
If someone has uploaded a file while filling in Form 1, but incorrectly fills in one of the other required fields, then the upload field gets cleared and they have to re-upload the same file they've already uploaded in order to submit. So what happens is:
1. Fill in form, upload a file, submit form.
2. If a required field is accidentally left blank, error occurs, error message prompts user to fill in the empty field
3. User fills in empty field, submits form.
4. Error occurs because suddenly the upload field is blank – it is cleared when the form refreshes with the first error message. New error message prompts user to upload a file.
5. User re-uploads the same file they've already uploaded, re-submits.
So the first problem is that the upload field is getting cleared, which causes confusion. I'd like it to remain populated with the file that's been uploaded.
Second problem – what's actually happening is that files are getting uploaded (at least) twice – once every time a submission attempt is made. So when the form is eventually successfully submitted, I get multiple identical copies of the same file. Because each time they upload a file, that additional file is getting attached to the form; the first upload is still attached to the form, it's just that the field is cleared and the form forgets that there's a file there.
Third problem – as a result of problem 2, I have checked the box that says 'do not email attachments' on Form 1. Because suddenly I'm getting emails around 20Mb in size (3 or 4 copies of the same 5Mb file). But with the multi-form, there is no 'do not email attachments' checkbox on Form 2, because there's no upload field on that form. So I get emailed the attachments anyway.
Get anyone help with these things? Am I doing something wrong, or is this a bug?
Thanks
|
|
|
Moderator
| Paul Amsterdam, NL posts 421 5:16 pm January 23, 2012
| |
|
|
Hi!
Thanks for detailed bg info, I'm afraid that that might be a short coming/bug of cforms.
Like you said, for multi-page forms, you apparently can't suppress attachments.
As far as re-submitting a form with an upload field is concerned (in case of an invalid earlier attempt), that's a browser related issue: once a form submitted the upload field is cleared.
I guess cforms could detect that invalid attempt and remove the file.
I'll forward this to Oliver.
Paul.
|
|
|
|
|
Guest
| Simon 11:24 pm January 29, 2012
| |
|
|
Thanks for the reply Paul.
Here's a fourth problem that I've just noticed: a few people are submitting forms without any attachments. This shouldn't happen, because the upload field is required. If someone leaves it blank and tries to submit, they should get an error message to tell them that the field is blank and that they need to upload something. If the file is too big, they should get an error message to say the file's too big. Most of the entries received so far are fine, but occasionally I'm getting entries that have file references (i.e the name of the file is there in the 'please upload a file' section), it's just that the file is not attached to the email, and most importantly, it isn't present on the server either. So I'm having to go back to these people and ask them to email me the things that they tried to upload, which is frustrating.
Here's what I get in the site's error log:
[29-Jan-2012 19:35:22] PHP Warning: move_uploaded_file(/tmp/phpEViRpD) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in /[home]/public_html/wp-content/plugins/cforms/lib_aux.php on line 310
[29-Jan-2012 19:35:22] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpEViRpD' to '/[home]/public_html/wp-content/uploads/application2012/xx-CV.doc' in /[home]/public_html/wp-content/plugins/cforms/lib_aux.php on line 310
Any ideas?
|
|
|
Moderator
| Paul Amsterdam, NL posts 421 12:15 pm January 30, 2012
| |
|
|
Hi!
I just tested the "required" setting for an upload field and couldn't find any issues, ie. a require upload field would not validate true if it wasn't set with a file.
Also and more importantly, based on your error log, the error appears to happen server side, since at this point the browser _did_ try to upload something (otherwise no attempt would be made to move the file from the /tmp space).
So my guess is, that something between the attempt to upload the file and moving the file happened…
..perhaps something for your hoster to take a look at as well (filename conventions/PHP settings /file…folder permissions etc.).
Paul.
|
|
|
|
|
Admin
| Oliver Munich, Germany posts 6237 7:26 am January 31, 2012
| |
|
|
Simon said:
I have a two-part multi-form. Form 1 has an upload field (required), Form 2 does not.
If someone has uploaded a file while filling in Form 1, but incorrectly fills in one of the other required fields, then the upload field gets cleared and they have to re-upload the same file they've already uploaded in order to submit. So what happens is:
1. Fill in form, upload a file, submit form.
2. If a required field is accidentally left blank, error occurs, error message prompts user to fill in the empty field
3. User fills in empty field, submits form.
4. Error occurs because suddenly the upload field is blank – it is cleared when the form refreshes with the first error message. New error message prompts user to upload a file.
5. User re-uploads the same file they've already uploaded, re-submits.
So the first problem is that the upload field is getting cleared, which causes confusion. I'd like it to remain populated with the file that's been uploaded.
unfortunately that's (using HTML and not flash) inherently not possible. when the form is reloaded the upload field will always be active, and without the earlier selected path/file.
HTML spec doesn't support pre-defining this field.
alternatively, I could disable the field entirely, but that would require extensive IQ to track and understand if a file has been uploaded already (no tracking ID has been given yet!)…
Second problem – what's actually happening is that files are getting uploaded (at least) twice – once every time a submission attempt is made. So when the form is eventually successfully submitted, I get multiple identical copies of the same file.
this shouldn't happen for either single or multi-page forms as files don't get moved from the /tmp space until the form validates 100%. In fact I just tried that and it works as expected.
However, if eg. you have uploaded a file via form #1, and now being on form #2 click the form's 'Back' button and resubmit form #1 with a different file, then yes, you'll end up with two files.
Because each time they upload a file, that additional file is getting attached to the form; the first upload is still attached to the form, it's just that the field is cleared and the form forgets that there's a file there.
Third problem – as a result of problem 2, I have checked the box that says 'do not email attachments' on Form 1. Because suddenly I'm getting emails around 20Mb in size (3 or 4 copies of the same 5Mb file). But with the multi-form, there is no 'do not email attachments' checkbox on Form 2, because there's no upload field on that form. So I get emailed the attachments anyway.
yes, that part needs to be revised to allow turning email attachments on/off for the last form in a mp form series even though the last form doesn't per se have an upload field.
Two workarounds:
- add an upload field to the last form, flag it 'disabled', and use CSS to hide it
- or move your upload fields (at least one) to the last form
|
|
|
|
|
Guest
| Simon 4:25 am February 2, 2012
| |
|
|
Thanks for the reply, Oliver.
this shouldn't happen for either single or multi-page forms as files don't get moved from the /tmp space until the form validates 100%. In fact I just tried that and it works as expected.
Ok – I'm probably misinterpreting the results, then. I am getting submissions with multiple copies of exactly the same file, and my assumption was that it was as a result of people not filling the first form in correctly. I suppose I thought this because the people filling the form are notoriously bad at following instructions! Does it make sense that the multiples are occurring as a result of going BACK from the second form? Form 2 consists mainly of a success message for Form 1 that prints the form fields so that people can check what they're submitting. As in: 'here are your answers: read them back to check you're happy with them' and then there are three buttons: START FROM SCRATCH / GO BACK AND EDIT A FIELD / SUBMIT. The flow would be like this:
1. Fill in Form 1, upload files, progress to Form 2 (Form 1 has therefore validated)
2. Read back answers, realise they made a spelling error, click EDIT to return to Form 1
3. Amend entry, resubmit Form 1, get error that upload field is blank (because they get cleared)
4. Reupload the thing that has already been uploaded
Actually, now that I've written that out, I've just checked the server, because I was wondering how multiple files could exist with the same file name. I should have done that in the first place, I don't know why I didn't. Looking at the last submission I received, the attachment was P500005.jpg. I received this twice. There's only one file on the server called P500005.jpg, so it's not the case that two files are being uploaded separately. If it's being uploaded twice, then the first one is getting overwritten. But this one file is getting attached to my notification email twice. Obviously then if I can turn off sending attachments at Form 2, then the problem is solved. There's still a small issue of people having to upload the file every time the field is cleared, but if that's a fundamental limitation of html then I'll have to live with that.
Thanks
|
|
|
Admin
| Oliver Munich, Germany posts 6237 6:55 am February 2, 2012
| |
|
|
Your form submission process is fine and shows best practice & your logic is spot on: when going back to form #1 the user really must pick the same (but could also pick a different file!) to complete the form again, which results in adding a file instance to the SESSION. this means that you indeed could end up with more than one file for the given submission.
What I can add however is logic around only keeping one instance of an uploaded file (based on filename), that way even multiple uploads of the same file only cause one data entry. 'Hope that made sense… ;)
Actually, now that I've written that out, I've just checked the server, because I was wondering how multiple files could exist with the same file name. I should have done that in the first place, I don't know why I didn't. Looking at the last submission I received, the attachment was P500005.jpg. I received this twice. There's only one file on the server called P500005.jpg, so it's not the case that two files are being uploaded separately. If it's being uploaded twice, then the first one is getting overwritten.
correct, but if the second submission would include a different file, you would end up with more than one file.
But this one file is getting attached to my notification email twice. Obviously then if I can turn off sending attachments at Form 2, then the problem is solved. There's still a small issue of people having to upload the file every time the field is cleared, but if that's a fundamental limitation of html then I'll have to live with that.
yes indeed, other more flexible alternatives would include flash etc. but that's beyond the scope.
I just sent you a beta copy (fixing the 'disable attachment' setting per form).
|
|
|
|