If you’re using the Wix Form app it may be possible (depends on the form).
If you built your own custom form from scratch the it’s definitely possible (but you can also submit the data without assigning it to an input element).
Any way, if you go for the hidden field, make the input elem hidden and:
import wixLocation from "wix-loaction";
const query = wixLocation.query;
const id = query.id;
//retrieve the GTM
$w.onReady(() => {
$w("#input7").value = gtm;
$w("#input8").value = id;
})