yesvee Posted December 8, 2012 Share Posted December 8, 2012 Hi 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.. yesvee Quote Link to comment https://forums.phpfreaks.com/topic/271754-losing-files-selected-for-upload-after-entering-wrong-recaptcha-code/ Share on other sites More sharing options...
berridgeab Posted December 8, 2012 Share Posted December 8, 2012 No, you lose control of a file after it has been posted. I think this is for security reasons, Quote Link to comment https://forums.phpfreaks.com/topic/271754-losing-files-selected-for-upload-after-entering-wrong-recaptcha-code/#findComment-1398252 Share on other sites More sharing options...
yesvee Posted December 8, 2012 Author Share Posted December 8, 2012 do i have any options other than showing a warning message to user to upload the files again... Quote Link to comment https://forums.phpfreaks.com/topic/271754-losing-files-selected-for-upload-after-entering-wrong-recaptcha-code/#findComment-1398253 Share on other sites More sharing options...
kicken Posted December 8, 2012 Share Posted December 8, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271754-losing-files-selected-for-upload-after-entering-wrong-recaptcha-code/#findComment-1398277 Share on other sites More sharing options...
Christian F. Posted December 9, 2012 Share Posted December 9, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271754-losing-files-selected-for-upload-after-entering-wrong-recaptcha-code/#findComment-1398328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.