Re-run the gform_file_upload_markup filter on failed submission

I am using the filter: gform_file_upload_markup to modify the markup displayed when an image uploaded. However the issue is:

Load form for the first time, upload an image - the filter runs and changes the markup which is output - correct and working.

If the form is submitted, fails for whatever reason (you’ve missed an input), the images are still attached to the form which is great, however the markup is not the custom markup anymore, because those filters only run when you hit the file-upload and select an image. Therefore, what I have displayed is just the image filename.png for example.

Screenshot 1 - the form failed, page reloaded. Images are still technically attached to the form but the gform_file_upload_markup did not run, so the default markup is used instead:

Code: this is the markup which is used when an image is uploaded. This does not run when the form fails and page is reloaded. Seems normal but just wanted to try get it to do so.

  // This function will render the uploaded image in a dynamically generated <img> tag to preview to the user.
  gform.addFilter('gform_file_upload_markup', function (html, file, up, strings) {

    var tmpPath = ''+ path +'/tmp/';
    var formId = up.settings.multipart_params.form_id,
    fieldId = up.settings.multipart_params.field_id;
    var fileName = up.settings.multipart_params.gform_unique_id + '_input_' + fieldId +'_'+ file.target_name;

    html = "<div class='dynamic-image__item' style='background-image:url(" + tmpPath + fileName + ");' onclick='gformDeleteUploadedFile(" + formId + "," + fieldId + ", this);'><span class='dynamic-image__close-cta' alt='" + strings.delete_file + "' title='" + strings.delete_file + "'></span></div>";
    return html;

I realised my mistake, for starters should have read the documentation better.

The JS gform_file_upload_markup filter only runs on the first launch of a form, if you reload that form or it goes to the next ‘step’, you will need to modify the markup using the PHP version of gform_file_upload_markup.

Summary: use BOTH filters, not just JS or the PHP version(s).

I’ve added the PHP version and now, when the form reloads because something failed, the markup is taken from the PHP filter, perfect!