Autopopulate Contact Form 7 file upload field from HTML <input type="file">

Viewed 75

Issue: I can't find a way to autofill a file upload field.

Backstory:

I'm very new to jquery and I made this code based entirely off of google searches. Granted, it has worked perfectly so far, but I don't quite know how exactly. You might have to dumb down your answers for me.

I wanted a free alternative to conversational forms, so I made a hidden cf7 form at the bottom of a page that is autofilled using jquery. Certain button clicks on the page add certain values to form fields. This works well for text based fields but I don't know how to make it work for a file field.

Scenario:

I have a cf7 field:

[file* decoration-customization-picture id:decoration-customization-picture]

and earlier on in the page, I have an html input field:

<input type="file" id="decorfile" name="decorfile">
<button type="button" id="fileupload1" name="fileupload1">Next</button>

Here's the format I have in mind for populating this field:

  $('#fileupload1').click(function(e) {    
        $('#decoration-customization-picture').val(#decorfile);    
  e.preventDefault(); 
    });

The issue is I have no idea what to add in the val() or any alternative approach to this.

If you would like more context, this is the webpage in question. https://teet.com.pk/tailor-my-dessert

0 Answers
Related