How to get WordPress post ID of last visited page?

It would be best to include this in your link. For example, the link to your form could be https://domains.com/form/?product=20. That way the product ID will be available as as GET parameter, eg $_GET['product'].

error code: 523