I know that you can autopopulate forms using a query string in the page URL.
You can use a static string if you know where traffic is coming from (email campaign, ads, social post, etc.). Change the query for each channel to populate the right field in this use case. I love this because it works for hidden fieds as well.
Is this what you are using when you mentioned the function you have implemented to check referral path?