Thank you your code worked for me!! Took some time for me to figure it out as someone without coding knowledge but I was able to change the contact form so that I know which page (not necessarily product) the form was submitted, by adding the following to the contact form section code:
{%- if page_title -%}
{%- endif -%}
This was based on your code and luckily I got it to work!