views:

21

answers:

2

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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?

A: 

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.

Tom Gullen
+1  A: 

Classic ASP doesn't support 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.

bobince