Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 807
djmzfKnm Avatar asked Sep 06 '10 07:09

djmzfKnm


2 Answers

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.

like image 132
bobince Avatar answered Sep 29 '22 09:09

bobince


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.

like image 29
Vance Coleman Avatar answered Sep 29 '22 10:09

Vance Coleman