The built in help has an example of how to send data back from UI template to node-red.
Also, on the forum, search scope send
in the Dashboard category.
Here is one such example: Upload file to SQL table - #4 by Steve-Mcl - check out the ui_template named "Upload Button"
Alternatively, you could create a http endpoint flow to receive data & use Ajax in your template to POST data back to node-red.