Jump to content


Losing Files Selected For Upload After Entering Wrong Recaptcha Code


  • Please log in to reply
4 replies to this topic

#1 yesvee

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 December 2012 - 05:14 PM

I have a form which collects information from a user, it also has an option to upload files. I placed a recaptcha control on the form to avoid bots. However the problem is i have many fields on the form which are lost if i give a wrong captcha.

I'm using hidden fields to store input values, so if user enters wrong captcha i'm restoring field values from the hidden fields, however i don't know how this can be done if the input type is file. Is it possible to store file info in the hidden field too, is yes how?

at the moment it is major problem if user enters wrong code after selecting some files.

Thanks for any input..

#2 berridgeab

  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts
  • LocationBirmingham, United Kingdom

Posted 08 December 2012 - 06:47 PM

No, you lose control of a file after it has been posted. I think this is for security reasons,

#3 yesvee

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 December 2012 - 06:56 PM

do i have any options other than showing a warning message to user to upload the files again...

#4 kicken

  • Gurus
  • Wiser? Not exactly.
  • 3,289 posts
  • LocationBonita, FL

Posted 08 December 2012 - 10:18 PM

You can save the file to your server when they first post it, somewhere temporary with a unique id to reference it.  If there were errors on the form, then print out some message indicating they have uploaded that file and a hidden field to track it's ID.

That is pretty much the only way to handle it.  There is no way to re-populate a file input or anything similar.

Recycle your old CD's, don't trash them!
Did I help you out? Feeling generous? I accept tips via Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 Christian F.

Christian F.
  • Staff Alumni
  • Advanced Member
  • 3,106 posts
  • LocationNorway

Posted 09 December 2012 - 06:02 AM

One possible way to make this easier for your users, is to add a AJAX call to the ReCaptcha field. In addition to the server-side checking. That way you can have the ReCaptcha tested, before you submit the rest of the form, if the user has JS enabled.
Should the test fail, then regenerate it (using the server-side code), replace it (with the JS-code), and stop the form from posting.
Keeping it simple.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users