Re: FileField doesn't repopulate after a ValidationError on another field
On Thu, Oct 30, 2008 at 12:19 PM, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: > > Ok, this sounds logical to me. > > I guess the best way to handle this is to make the uploading process > require 2 separate submission pages, the first one for all the regular > input, and then have a second page just to upload the file. > > Perhaps somebody has a better idea? > At the expense of some additional complexity in your view & template, you can maintain a one-step submission for your users. I'd probably look at adding an additional hidden input field to the form that starts out empty but is used in cases where a file has already been uploaded through a prior submission which failed validation for some non-filefield-related problem. The value in the hidden field would allow the server view code to locate the previously-uploaded file when the form is re-submitted. The template would display the File input field only when necessary, if a file has already been uploaded then the template would display a note to that effect instead. So if there are no errors on the initial submission, it's a one-step process for the user. If there is an error (not related to the uploaded file), the server stashes the uploaded file somewhere and sets the value of the hidden field so that the file can be found on resubmit. From a user's point of view the form is redisplayed but they do not have to re-select the file -- rather the form shows that the file has been uploaded and the other error messages on the form show what needs to be corrected to complete the submission. On resubmit, the server locates the previously-uploaded file via the information in the hidden field instead of getting it from the post data. Your view logic is a bit more complicated than for simple forms, and your template has to be a little more involved than {{ form.as_p }}, but it's probably more intuitive for users than a 2-step default submission process. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FileField doesn't repopulate after a ValidationError on another field
Ok, this sounds logical to me. I guess the best way to handle this is to make the uploading process require 2 separate submission pages, the first one for all the regular input, and then have a second page just to upload the file. Perhaps somebody has a better idea? Thanks On Oct 30, 5:42 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Thu, Oct 30, 2008 at 10:52 AM, [EMAIL PROTECTED] < > > > > [EMAIL PROTECTED]> wrote: > > > Hello, > > > I've having a problem with FileField and ImageField. Basically, I have > > a form for uploading images: > > > Name: _a_ (throws ValidationError('This name is already taken. Choose > > another')) > > Notes: _test notes_ > > Filename: _abc123.txt_ > > > When I press SUBMIT, I get the form again, but it looks like this: > > > -This name is already taken. Choose another > > Name: _a_ > > Notes: _test notes_ > > Filename: _ (blank Not sure why) > > > The FileField is not repopulated for some reason, but the other fields > > are. > > I believe this is a browser security measure. The browser won't allow a > server to pre-load a value into a File input, because that would mean a > naive user could easily submit a form which uploads some key file from their > machine to the server. So for a File input the browser requires that the > user actually go and select a file to upload. (I do not know if there are > any tricks one can play to get around this, I've never looked for one.) > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FileField doesn't repopulate after a ValidationError on another field
On Thu, Oct 30, 2008 at 10:52 AM, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: > > Hello, > > I've having a problem with FileField and ImageField. Basically, I have > a form for uploading images: > > Name: _a_ (throws ValidationError('This name is already taken. Choose > another')) > Notes: _test notes_ > Filename: _abc123.txt_ > > When I press SUBMIT, I get the form again, but it looks like this: > > -This name is already taken. Choose another > Name: _a_ > Notes: _test notes_ > Filename: _ (blank Not sure why) > > The FileField is not repopulated for some reason, but the other fields > are. > I believe this is a browser security measure. The browser won't allow a server to pre-load a value into a File input, because that would mean a naive user could easily submit a form which uploads some key file from their machine to the server. So for a File input the browser requires that the user actually go and select a file to upload. (I do not know if there are any tricks one can play to get around this, I've never looked for one.) Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FileField doesn't repopulate after a ValidationError on another field
Hello, I've having a problem with FileField and ImageField. Basically, I have a form for uploading images: Name: _a_ (throws ValidationError('This name is already taken. Choose another')) Notes: _test notes_ Filename: _abc123.txt_ When I press SUBMIT, I get the form again, but it looks like this: -This name is already taken. Choose another Name: _a_ Notes: _test notes_ Filename: _ (blank Not sure why) The FileField is not repopulated for some reason, but the other fields are. Using django-1.0 I bind the data as specified at http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-file-uploads: form = UploadNewImageForm(request.POST, request.FILES) My view function is identical to the one on the example page. Everything else works, the file is properly uploaded and there are no other problems. It is really just a user interface issue I would like to fix because it is very annoying to have to repopulate the form every time there is an input error, especially if there are many fields. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---