Apologies for the long explanation. I have a form built using the From API that is used as a profile for users. It allows users to upload a CV/resume type file for themselves and it is mandatory to upload a file or the user cannot complete the form.
Uploading and saving the files are no problem, but I run into problems when the user tries to update their form. The file input type in the Form API doesn't have a
#default_value option (understandably) which means that when the user comes to edit the form, there are two problems.
The first is that it shows a blank file upload field and the user is expected to upload a file again (as the field is mandatory). This is confusing for the user and means that more than one file can be assigned to a user. The second is that the user does not have an option to remove their file and add a new one to replace it.
What I would like to do is write a function that checks to see if the form is being accessed by a logged in user, checks if that user has a file associated with them and displays the field appropriately. If a file exists, display the name of the file and a link to remove it instead of showing the file upload field.
I could do most of this no problem, but the extra part I would like and can't do is for the "Remove file" link to be an AJAX call that would delete the user's file and then display the file upload field dynamically. Has anyone done something like this before?