Can you re-populate file inputs after failed form submission with PHP or JavaScript?

前端 未结 2 1405
孤独总比滥情好
孤独总比滥情好 2020-11-28 10:51

Okay so here\'s the scenario:

User is presented with form that contains file inputs. User submits form. Form does not pass validation/verification for one reason or

相关标签:
2条回答
  • 2020-11-28 11:03

    I think the short answer here is no. You can't repopulate file upload fields. However, you can work around it.

    If a file has been selected and the form submitted, then you've already received the file. What you can do is keep a reference to the file on disk and put that in a hidden field and show a message to indicate to the user you still have their file uploaded so it does not need to be replaced/re-uploaded. When your form gets submitted again without a file, you can check for the hidden field value and use that to get your local copy of the file they uploaded in their last attempt.

    The other way to do this is to either submit the form via ajax (using either flash or the iframe method for the file upload) or to do an ajax call to validate the form first, and then only submit as normal if valid (thus no form reload, no loss of file upload field data).

    0 讨论(0)
  • 2020-11-28 11:09

    I solved this problem by let user pick upload file as the last field before submit the form ^^

    0 讨论(0)
提交回复
热议问题