[英]how to alert filename of uploaded file in squarespace form?
I have a form on a page in SquareSpace that allows an image file to be uploaded:-我在 SquareSpace 的页面上有一个表单,允许上传图像文件:-
https://www.colourourstory.com/uploads (try with dummy data if needed). https://www.colourourstory.com/uploads (如果需要,尝试使用虚拟数据)。
I need to add the filename of the uploaded image to a hidden field named "SQF_FILENAME" which already exists.我需要将上传图像的文件名添加到已经存在的名为“SQF_FILENAME”的隐藏字段中。
Any tips on how do I do this please as the value is only available after a successful upload?请提供有关如何执行此操作的任何提示,因为该值仅在成功上传后可用?
Thanks谢谢
Jonathan乔纳森
I can suggest using some jQuery.我可以建议使用一些 jQuery。
For example, you can hook a function to the change event of the input[type="file"]
and grab its value.例如,您可以将 function 挂钩到
input[type="file"]
的更改事件并获取其值。 Then all you need to do is set the value to your hidden field.然后,您需要做的就是将值设置为隐藏字段。
Here is a short code example:这是一个简短的代码示例:
$('.form-block').on('change', 'input[type="file"]', function() { console.log($(this)); console.log($(this).val()); const fileName = $(this).val().split('C:\\fakepath\\').pop(); $('input[name="SQF_FILENAME"]').val(fileName); });
Hope this helps.希望这可以帮助。
Cheers.干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.