Request.Form - Getting null responses [duplicate] - asp-classic

I have following form,
<form action="contact_us.asp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="firstname" type="text" id="firstname" size="30" />
<input name="lastname" type="text" id="lastname" size="30" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
But when I am trying to get value of these post variables in my ASP file contact_us.asp then it returns blank. Code is below:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<%
Dim FirstName, LastName, Email, Message
FirstName = request.form("firstname")
LastName = request.form("lastname")
response.write(FirstName & "OK")
%>
Its returning only "OK" to me. nothing in Message variable?
Please help me and tell me what's wrong here?

Classic ASP doesn't provide built-in support for working with `multipart/form-data. This is a surprisingly basic deficiency even for a language of ASP's venerable age, but what're you gonna do about it, move to ASP.NET? (Yes? oh. well never mind then.)
If you aren't doing file uploads, it's easiest just to stick with the default enctype (which is application/x-www-form-urlencoded). The only advantage of multipart/form-data is that you can put file uploads in it. (Theoretically, it would also have the advantage that you can specify character encodings definitively. But no browser actually does that.)
If you do need to handle multipart/form-data in Classic ASP you will need to parse the incoming request body yourself, splitting it into fields and values. Or rather, more typically, use an existing library to do it*.
That library will usually provide separate interfaces for reading the uploaded files and the other form values. This completely replaces use of the Classic ASP Request.Form interface. Exactly where you can find it depends on the library you choose. This does mean that if you want to have a form that can respond to either enctype equally you have to check the type and use one of the two different interfaces.
*: There are loads. for example. I'm not endorsing either of these as such... neither of them actually parse multiparts properly as per the standard and both seem a bit lax about filename security (never store a file under the user-submitted filename! security disaster!). But that seems to be par for the course for ASP upload scripts. At least, unlike many, they're not asking money for them.

I found by removing enctype completely (which defaults to application/x-www-form-urlencoded) from the form tag that Request.Form("SomeInputTagId") worked fine with method="post". I also didn't need to install any third party readers. Hope this helps.

Don't use enctype="multipart/form-data"
Remove that from the code and see if it works. The form-data enctype is used for uploading data, for example image files. You need to access the form elements slightly differently if you use that enctype.
If you are uploading data, then the ASP object you are using (for example ASP Upload) will have functions to access form fields. Request.form("") wont work.
Accessing the form values would be along the lines of:
Set yourUploadComponent = CreateObject("Your.UploadComponentClassString")
sFormValue = yourUploadComponent.Form.Item("txtName").Value
You will need to read the objects documentation.

Related

How can I create Simple aspx webpage which will send me parameters in the link

I am trying to do something from scratch in asp
I would like to get something like below. From basic hard coded values.
http://localhost:2478/Default.aspx?phone=905123456&order=123456
After that I want to use this parameter in my variables for SQLquery
I am new to asp.net and vb , I'm learning. Can you please explain me in details? Any helps will be appreciate.
Can you please provide any basic code from where I can start
Based on your latest comments:
<form method="get" action="default.aspx">
<input type="text" name="phone" />
<input type="text" name="order" />
<input type="submit" value="submit" />
</form>
Key points:
method=get (fields are in url instead of body)
note that the form above doesn't have runat=server (more below) - it's a plain HTML Form on plain HTML page
in the context of ASP.Net Web forms, you may run into issues particularly if you are using Master Pages (you can't nest forms, and a Master page is a container for your entire page).
ASP.Net forms do POSTbacks - re: method=post
You can use/add plain forms in an ASP.Net page as long as you don't nest them (outside of the server side ASP.Net form).
If you have no choice (e.g. Master Page), you'll have to construct the Querystring manually after a POSTback, then Response.Redirect to some other target (adding the querystring manually).
there are other non-ASP.Net-y ways of doing it - e.g. javascript, but that a different story

ASP: request.form is not returning value?

I have following form,
<form action="contact_us.asp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="firstname" type="text" id="firstname" size="30" />
<input name="lastname" type="text" id="lastname" size="30" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
But when I am trying to get value of these post variables in my ASP file contact_us.asp then it returns blank. Code is below:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<%
Dim FirstName, LastName, Email, Message
FirstName = request.form("firstname")
LastName = request.form("lastname")
response.write(FirstName & "OK")
%>
Its returning only "OK" to me. nothing in Message variable?
Please help me and tell me what's wrong here?
Classic ASP doesn't provide built-in support for working with `multipart/form-data. This is a surprisingly basic deficiency even for a language of ASP's venerable age, but what're you gonna do about it, move to ASP.NET? (Yes? oh. well never mind then.)
If you aren't doing file uploads, it's easiest just to stick with the default enctype (which is application/x-www-form-urlencoded). The only advantage of multipart/form-data is that you can put file uploads in it. (Theoretically, it would also have the advantage that you can specify character encodings definitively. But no browser actually does that.)
If you do need to handle multipart/form-data in Classic ASP you will need to parse the incoming request body yourself, splitting it into fields and values. Or rather, more typically, use an existing library to do it*.
That library will usually provide separate interfaces for reading the uploaded files and the other form values. This completely replaces use of the Classic ASP Request.Form interface. Exactly where you can find it depends on the library you choose. This does mean that if you want to have a form that can respond to either enctype equally you have to check the type and use one of the two different interfaces.
*: There are loads. for example. I'm not endorsing either of these as such... neither of them actually parse multiparts properly as per the standard and both seem a bit lax about filename security (never store a file under the user-submitted filename! security disaster!). But that seems to be par for the course for ASP upload scripts. At least, unlike many, they're not asking money for them.
I found by removing enctype completely (which defaults to application/x-www-form-urlencoded) from the form tag that Request.Form("SomeInputTagId") worked fine with method="post". I also didn't need to install any third party readers. Hope this helps.
Don't use enctype="multipart/form-data"
Remove that from the code and see if it works. The form-data enctype is used for uploading data, for example image files. You need to access the form elements slightly differently if you use that enctype.
If you are uploading data, then the ASP object you are using (for example ASP Upload) will have functions to access form fields. Request.form("") wont work.
Accessing the form values would be along the lines of:
Set yourUploadComponent = CreateObject("Your.UploadComponentClassString")
sFormValue = yourUploadComponent.Form.Item("txtName").Value
You will need to read the objects documentation.

ASP.NET ValidateRequest & XML in Standard HTML Forms

I have a very basic ASP.NET web site. It has a single page (TestPage.aspx) that I want to be able to launch using a POST request with some XML input. The basic HTML page that launches the request looks like this:
<html>
<head>
</head>
<body>
<form action="http://webserver/TestPage.aspx" name="Launch" method="post">
<input type="hidden" name="XMLmsg" value="<initialize>...</initialize>">
<input type="submit" value="Submit">
</form>
</body>
</html>
When the TestPage launches, however, I get the easily 'Google-able' "A potentially dangerous Request.Form value was detected from the client" error message.
It seems like the solution would be to put ValidateRequest="false" into my TestPage.aspx file, right? I thought so, too. And the internet told me the same thing. The only problem is...that didn't change anything. I still get the error.
I really need to be able to parse this XML. What can I do?
Well, I finally managed to get a solution to my problem, even if it's not perfect.
You can follow this link to a forum post where the whole process is tracked. The gist of it is that even added the necessary attributes didn't stop ASP.NET from validating requests from a standard HTML page, so I had to resort to writing a CGI app to accept the request and parse the inputs before sending back the necessary response.
For information on writing CGI for ASP.NET you can go here.
Is it optimal? No.
Is it clean? Not exactly.
Does it work? Yes.

Post a form from asp to asp.Net

I have a classic asp application. I want to post a contest form from that page to an Asp.Net form. The reason is that I want to use a lot of logic i have built into an Asp.Net page for validation before entering into the database and I don't know asp very well. Not to mention asp.Net being more secure.
What's the best way to accomplish this goal? My thoughts are as follows:
My asp Page:
<html>
<body>
<form action="/Contests/entry.aspx" method="post">
Name: <input type="text" name="fname" size="20" />
Last Name: <input type="text" name="lname" size="20" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
aspx page is running in a Virtual Directory and would handle anything posted to it.
Is this possible, or does aspx prevent this kind of thing?
I ( preferably ) don't want to create the form in aspx as my colleague wants to have control of the page and build the html himself and I don't want the hassle of constantly changing it.
Are there caveats I need to consider?
What roadblocks will I run into?
How do I access the Posted Form Values? Request.Form?
Yes it is possible. In general, a POST is a POST. So you can post from a PHP page to a .NET page if you wanted. You would access the Request.Form variables just as you do now. You will have to look at the ASP Classic page to see the names of the post items but in general, you can access them as if you had pasted from .NET page.
This can be done and works fine. You will access the Posted Form values as you said via Request.Form.
I think the biggest caveat is that you will need to handle invalid data in some way - typically with a webform the .aspx page would be displayed again with validation errors, but that would likely be inappropriate for your circumstance. Probably you will need to redirect them back to the .asp page with query string parameters indicating the failures and the page will need code allowing it to fill in the form fields with their previous values and display the error message.
How about calling an ASP.NET webservice from classic asp?
https://web.archive.org/web/20210125161040/http://www.4guysfromrolla.com/webtech/070302-1.shtml

Asp.net + Google Charts - Attached html file won't open correctly

I have an Asp.Net page containing one grid and an image. The image is a google charts chart and its urls is around 1600 characters. I out together an .htm file containing the grid and the image. For the grid I use RenderControl to get its html code, and for the image, I just add an img html tag and assing the url to its src. I then send this .htm file as an email attachment.
My problem is that when you try to open the attached file, you see everything ok except the image (it doesn't show anything and when you look at the source code for the page, the img tag doesn't show any src whatsoever - it just shows < img > (without the spaces). If you open the file after you save it to disk, then it all works fine and you see the actual img src. Why???
Here's my html header:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>
And here's the image:
<img src="http://chart.apis.google.com/chart?chd=t:0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,420.95,0.00,2725.25,0.00,0.00,0.00,0.00,5036.96,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,47.82|0.0000,7.97,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.98,1.99,2.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.99,1.99|0.5100,34.04,0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,36.77,18.01,18.26,0.00,0.00,0.00,0.00,0.00,8.99,0.00,20.06,14.01|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,2.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.00|3.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,46.98,0.00,257.91,113.25,0.00,0.00,0.00,1.00,24.99,29.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,60.00,123.92|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,45.00,0.00,0.00,0.00,0.00,0.00,0.00,20.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,84.00|0,55.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,65.99&chdl=Type 1|Type 2|Type 3|Type 4|Type 5|Type 6|Type 7&chco=000000,CD7F32,A62A2A,0000FF,00FF00,FF6EC7,A8A8A8&chds=0,5037&chxl=0:|6/22|6/23|6/24|6/25|6/26|6/27|6/28|6/29|6/30|7/1|7/2|7/3|7/4|7/5|7/6|7/7|7/8|7/9|7/10|7/11|7/12|7/13|7/14|7/15|7/16|7/17|7/18|1:|0|503|1006|1509|2012|2515|3018|3521|4024|4527|5037|2:|Days|3:|Amount ($)&chls=3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0&chm=o,990066,0,-1,6.0|o,990066,1,-1,6.0|o,990066,2,-1,6.0|o,990066,3,-1,6.0|o,990066,4,-1,6.0|o,990066,5,-1,6.0|o,990066,6,-1,6.0&chg=3.85,0&cht=lc&chs=900x300&chxt=x,y,r,t"/>
If the problem is the size of the URL, what are my choices, short of building a pdf file and attaching it? It seems that an html file is all I need and I would like to keep it simple.
You could definitely be seeing a long URL problem. That happened to me when I was using Google Charts API (albeit in Rails rather than ASP.NET). I never could find the exact URL size that started to cause trouble, but some people reported troubles starting at 1024.
Google provides a couple of different encoding types you can use on the input data to shrink it, but using anything other than text encoding (what you are doing) will disable your ability to scale the data, if you care about that.
If you cannot scale the data, you may get some ugly graphs if the data stays at the maximum for long stretches or if you want to overlay two graphs with different scales.
See data formats from Google Chart API Docs
If the GET is too long you could use a POST instead you'll have a 16k limit which is more than enough. I've used the code below to generate your chart and it worked. So yes I guess you could use the post and attach that to the email. Perhaps the problem with using GET is an issue with the email client configured to not opening image files, have you tested it in other clients?
<form action='http://chart.apis.google.com/chart' method='POST' id='post_form'>
<input type="hidden" name="cht" value="lc" />
<input type="hidden" name="chtt" value="Demo chart" />
<input type="hidden" name="chg" value="3.85,0" />
<input type='hidden' name='chs' value='900x300' />
<input type="hidden" name="chxt" value="x,y,r,t" />
<input type="hidden" name="chds" value="0,5037" />
<input type="hidden" name="chxl" value="0:|6/22|6/23|6/24|6/25|6/26|6/27|6/28|6/29|6/30|7/1|7/2|7/3|7/4|7/5|7/6|7/7|7/8|7/9|7/10|7/11|7/12|7/13|7/14|7/15|7/16|7/17|7/18|1:|0|503|1006|1509|2012|2515|3018|3521|4024|4527|5037|2:|Days|3:|Amount ($)" />
<input type="hidden" name="chls" value="3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0" />
<input type="hidden" name="chm" value="o,990066,0,-1,6.0|o,990066,1,-1,6.0|o,990066,2,-1,6.0|o,990066,3,-1,6.0|o,990066,4,-1,6.0|o,990066,5,-1,6.0|o,990066,6,-1,6.0" />
<input type="hidden" name="chco" value="000000,CD7F32,A62A2A,0000FF,00FF00,FF6EC7,A8A8A8" />
<input type="hidden" name="chdl" value="Type 1|Type 2|Type 3|Type 4|Type 5|Type 6|Type 7" />
<input type='hidden' name='chd' value='t:0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,420.95,0.00,2725.25,0.00,0.00,0.00,0.00,5036.96,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,47.82|0.0000,7.97,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.98,1.99,2.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.99,1.99|0.5100,34.04,0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,36.77,18.01,18.26,0.00,0.00,0.00,0.00,0.00,8.99,0.00,20.06,14.01|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,2.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.00|3.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,46.98,0.00,257.91,113.25,0.00,0.00,0.00,1.00,24.99,29.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,60.00,123.92|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,45.00,0.00,0.00,0.00,0.00,0.00,0.00,20.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,84.00|0,55.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,65.99'/>
<input type="submit" />

Resources