[SalesForce] How to create simple HTML forms in Salesforce Marketing cloud email templates

I am trying to create a simple form with one or two fields in the email templates.I have created the same before in landing pages and I am not sure we can achieve the same in email templates .And my code sample is below which throws validation error.
Since the code is in email I don't where should I post any help regarding this will be helpful.

%%[
    var @test
    set @test="test survey"
    set @UrlThispg = RequestParameter('PAGEURL')
]%%
<html>
  <head>
  </head>
  <body>
  <p>
           hi welcome:%%=v(@test)=%%,URL is : %%=v(@UrlThispg )=%% 
  </p>
 <form id="formName" action="%%view_email_url%%" method="post" enctype="application/x-www-form-urlencoded">

<input type="text" name="id">
<input type="submit" value="submit">
<script runat="server" type="text/javascript" >
Platform.Load("core", "1");
if (Request.Method == "POST") 
{

}
</script>
</form>
</body>
</html>

Error I get during Generate Preview is

**An error occurred when attempting to execute a Javascript block. See inner exception for detail. Script: Platform.Load("core", "1"); if
(Request.Method == "POST") { }

ListID: 22920 Index: 16

Value cannot be null. Parameter name: value Line: 3 Char: 16 if
(Request.Method == "POST")

{
**

Best Answer

The VAWP URL is a personalization string, not an AMPScript variable, so it needs to be referenced differently.

%%[
    var @test
    set @test="test survey"
    set @UrlThispg = RequestParameter('PAGEURL')
    set @VAWP = AttributeValue("view_email_url")
]%%
<!-- snip -->
<form id="formName" action="%%=v(@VAWP)=%%" method="post" enctype="application/x-www-form-urlencoded">

or

%%[
    var @test
    set @test="test survey"
    set @UrlThispg = RequestParameter('PAGEURL')
]%%
<!-- snip -->
<form id="formName" action="%%view_email_url%%" method="post" enctype="application/x-www-form-urlencoded">

That being said, I'd suggest you look into utilizing the _messagecontext personalization string for determining if the email is being rendered via VAWP or not.

NOTE: Also keep in mind that the view_email_url is transient -- meaning if you are depending on data in your sending Data Extension, if that data is gone, there's a possibility that your VAWP destination will be broken.