Filefield upload validation during registration
macrodesign - May 2, 2009 - 17:14
| Project: | Content Profile |
| Version: | 6.x-1.0-beta4 |
| Component: | User registration module |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs work |
Description
Hi,
This site is for consultants, they review CV's if approved, approve and account that sends an email to the user that he is approved and he can use the site username and password.
To do this, content profile is the best module to use.
the following steps were done
1. Content type resume created, enabled as content profile
2. Filefield and appear in user registration enabled and REQUIRED option selected
everything is fine, some users are registering with CV's and some forget to CLICK ON UPLOAD. and gets registered without a prompt from system that they have forgot to press UPLOAD.
Please help me we are losing customers, i know nothing more than enabling and disabling.
Thanks
Danish

#1
I can confirm this behaviour on beta 4.
I performed the test by clicking save on the node without clicking the upload button. The expected behaviour is to upload on node save without having to explicitly click on the upload button.
I have tested this using
It is worth noting that this worked correctly under Drupal 5.
It is unclear whether this is being caused by content profile, CCK, filefield or node.
Any thoughts (or requests for further info) very much appreciated!
Danish- Did you resolve this issue?
#2
see Chrism,
I changed the workflow. using logintoboggan module. now users are login as soon as they create the account and directed to create resume page, on this page they create their resume and upload 1-2 files as required and it is working fine. But i failed to do it on 1 page i.e registration + resume.
#3
I can also confirm this bug, if you don't press the upload button during registration the file wont upload
#4
I had a developer look at it for a morning and he says that this is because the form handler on the user form is different from the form handler on the CCK form. He says that the one for the user/nodeprofile is much simpler, and while it can handle all the basic CCK widgets, it doesn't handle the filefield properly.
Can anyone make sense of this?
C.
#5
Marked #519726: FileField and Content Profile and #529768: Filefield doesn't work properly on nodeprofile as duplicates. This is a bug with Content Profile (or maybe an unwritten "feature") and not with FileField, since FileField is meant to work with CCK and Content Profile uses a bit of a hack to the user registration form since CCK wasn't actually meant to provide this sort of functionality.
#6
I never had a look at it or tried it.
From the README:
* Putting file uploads on the registration form is not supported and probably won't work right.
#7
Is it something we could look at? Do you think it might be hard to resolve? I don't mind taking some time to look at it, if I had some pointers in the right direction.
#8
Probably just something is missing form $form that filefield needs.
#9
I would be willing to sponsor $50 for the fix of this problem.
#10
I thought I was doing something wrong when I couldn't get this to work.
I don't know if I'm relieved or frustrated that it's not a simple fix.
+1 for getting this as a feature.
#11
I'm going to increase my bounty to $70 if fixed in the next 2 weeks. It would be very much appreciated!
#12
Hi chrism2671!
I think I have come up with a fix for this problem. Well, it's technically more of a "hack" than a fix.
You're right when you said...
So I decided to just approach this problem in a very straightforward manner.
Since you really just want to prevent users from submitting the form without first hitting the upload button, then I decided to address it by auto-uploading the selected file right after the user selects a file.
I added some jquery code to handle this. I added it directly to the filefield.js file inside the filefield module directory.
What I did...
I added the following code. (Please refer to attached file to find out where I inserted the following code).
// Auto-Press upload button
$(this).parent().find('input.form-submit').mousedown();
// Disable main submit button while uploading...
$('#edit-submit').attr('disabled', 'disabled');
What this does...
1. I added some jquery code to auto-press the upload button when the user selects a valid file. I got the idea from this post.
2. I added another piece of code to disable the submit button while it is uploading. This is to prevent the user from prematurely submitting the form when the file hasn't been successfully uploaded yet.
More code...
function checkIfUploaded() {
if ( $("div.filefield-file").length > 0 ) {
// Enable submit button
$('#edit-submit').attr('disabled', '');
}
else {
setTimeout("checkIfUploaded()", 1000);
}
return;
}
What this does...
It's a function that checks every 1 second if the upload widget has already been replaced with a preview widget (which means that it's done uploading), and if yes, enable the main submit button so that the user can submit the form.
There are some anticipated side-effects to this hack. One is that this will affect all filefield upload widgets of your entire site. They will all have the auto-upload functionality. This shouldn't be a problem, since it's actually what you really expect it to do, right?
Another side-effect is that this will only work on the current module version (filefield-6.x-3.1). And it might not work properly (or might not even work at all) on future upgrades of the module, since this is a hack. But this shouldn't be a problem if you are content with how filefield currently performs. You can just wait until filefield makes the feature you want built-in, and then you can make the upgrade.
It works in IE 7, Opera, Firefox, and Chrome.
I used filefield-6.x-3.1.
Directions:
1. Replace the filefield.js file in your filefield module directory with the attached file (Make sure that you rename the file to filefield.js).
That's it.
Should you have any questions or clarifications, don't hesitate to let me know. Thanks! Enjoy!
If you are satisfied with the quick fix, my paypal email is albertpadin(at)gmail(dot)com. The bounty will be greatly appreciated!
#13
Hi chrism2671!
I made a change in the checkIfUploaded() function. The change will make the hack work even in image file uploads using the filefield widget. I uploaded the modified custom_filefield.txt (please refer to attachment).
function checkIfUploaded() {
if ( $("div.widget-preview").length > 0 ) {
// Enable submit button
$('#edit-submit').attr('disabled', '');
}
else {
setTimeout("checkIfUploaded()", 1000);
}
return;
}
PLEASE USE THE CURRENT ATTACHMENT. You can disregard the previous one. Thank you!
I hope this has helped. Enjoy!
#14
The problem is this, thanks to firebug:
"Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form. The file will not be sent."
Attached is a patch that detects if the enctype is set in a node form, then sets it in the user registration $form.
#15
ah yep, of course the enctype has to be set. I've committed that fix, thanks.
I set the issue to fixed for now. I don't know if filefield works now, it might - feel free to reopen if it doesn't. Anyway I'm happy to add in (proper) fixes for that, but it's still "officially" not supported.
#16
Automatically closed -- issue fixed for 2 weeks with no activity.
#17
#18
Hi,
The hack provided at http://drupal.org/node/451654#comment-2029388 was really effective if people forget to click the upload button as it auto uploads the Browsed content.
I am using Content profile to expose fields at Registration which has a compulsory Upload Resume Field with an red (*) marking it as compulsory Field in Registration display.
Unlike other Compulsory fields if left empty displays a warning message that the field is required . this ain't working with the File Field Compulsory Upload Button Field exposed in registration.
Users Can Skip this field and Complete the registrations. I am too loosing out on Resumes due to this problem. Can Anybody having knowledge with the validation During registration check for the same.
Regards
#19
I replaced the js file and applied the patch.
This no longer seems to work with Filefield 6.x-3 and Content Profile 6.x-1.0-beta4
I have two required image filefields on my registration form and if I leave them empty, I can still submit the form without any validation warning.
If I choose browse and then dont choose upload and save the form, the images are not added or uploaded
If I choose browse and then upload for each and I submit the form they are still not attached
Any help with this would be greatly appreciated.
Thanks
Gregg
#20
Sorry i was wrong, it does work to upload the images but it does not respect the fact that the upload fields are required and so allows users to register without attaching any images.
#21
I have the same problem with Filefield 6.x-3 and Content Profile 6.x-1.0-beta4.
Thanks
Ben