Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2003, 04:26 PM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default Binary and Text data in one form

Hia all... This is my first post... Hope someone can help me out...


basically I'm setting up a form on my website which allows people to upload a file to my webserver AND add data to an Access Database.

Below is my form code:

<form name="form1" method="post" enctype="multipart/form-data" action="savekit.asp">
<input name="txtKitName" type="text" id="txtKitName" size="30" maxlength="50">
<select name="lstModule" id="lstModule" style="width:203">
<% While (NOT getModules.EOF) %>
<option value="<%=(getModules.Fields.Item("moduleID").Valu e)%>"
<%If (Not isNull("1")) Then If (CStr(getModules.Fields.Item("moduleID").Value) = CStr("1")) Then Response.Write("SELECTED") : Response.Write("")%> >
<%=(getModules.Fields.Item("moduleName").Value)% ></option>
<% getModules.MoveNext()
Wend
If (getModules.CursorType > 0) Then
  getModules.MoveFirst
Else
  getModules.Requery
End If
%>
</select>
<input name="txtDescription" type="text" id="txtDescription" size="30" maxlength="200">
<input name="file" type="file" id="txtFile" size="30">
<input name="Submit" type="submit" id="Submit" value="Submit">
<input name="Reset" type="reset" id="Reset" value="Reset">


This form (possiblt because of the "multipart/form-data" part) uploads the file to the webserver with no problems - However, it's NOT sending the form data in any way that I can see to the savekit.asp page where I'm collecting the data!?

Any ideas?


Big thanx to all who can shed some light!

 
Old December 12th, 2003, 06:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

When you post a form with enctype=multipart/form-data, the data for the other form fields, like your description field, is included in the HTTP header along with the uploaded file, but its not a trivial task to extract it from there using ASP.

I would suggest having two forms, one with multipart/form-data for the upload and the other data without this enctype. You'll just need a bit of javasxcript on the submit button to submit both forms at once (probably best if they submit to separate asp pages).

Let me know if you absolutely must have just one form, I can probably dig out some code to guide you in extracting the data from the HTTP header, but I warn you it won't be pretty :D

hth
Phil
 
Old December 12th, 2003, 06:31 AM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default

Thanx for the help... Although I *think* i must have one form... What do u reckon? Here is my situation...

The data (file upload) along with name and description gets sent to a page. The asp page checks to see if a file with that name already exists on the server... If it doesn't it saves the file and then enters the name, description, and Location details of the file into a database. Obviously if the file exists the user is sent back to the original page, the file is not uploaded and no information is entered into the database.

I searched the web for easier ways of doing this, but they are all too expensive for me :( So i just wrote this myself..

So do you think i'm on the right track? Any comments would be appreciated.


Thanx!

 
Old December 12th, 2003, 07:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK, you must have just one form then.

Take a look at RFC 1867 which defines multipart/form-data syntax, in particular section 6 which has an example HTTP header with both a file and other input data (ftp://ftp.isi.edu/in-notes/rfc1867.txt).

For asp code take a look at the source for this article http://www.asp101.com/articles/jacob/scriptupload.asp. The Sub Upload() shows how to search through the binary HTTP header and read the data it contains.

hth
Phil
 
Old December 12th, 2003, 08:50 AM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default

Is it at all possible to append my data form entries to the URL...

Ie, take the form data and pass it as a URL String..

E.g. ...uploadfile.asp?Name=TEST&Description=TEST2

Then on the UploadFile.asp page, I can easily extract the URL string and add that to a database entry and the binary data can be written to a file....

Or am I just being stupid?

Thanx again.

 
Old December 12th, 2003, 11:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Don't see why not. seems a much better way than messing around with binary data :)

Just use some js to change the action property of the form to uploadfile.asp?Name=TEST&Description=TEST2 before you submit.

Let me know how it goes...
 
Old December 12th, 2003, 11:05 AM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default

I'll try it sometime over the weekend and get back to ya - Maybe it will help others in someway...


Anyway. Thanx for your help!

 
Old December 12th, 2003, 11:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

LOL, I'm too impatient to wait that long. I just tried it and it works just fine. Nice idea :D
 
Old December 12th, 2003, 12:00 PM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default

Not bad considering i'm fairly new to ASP

 
Old December 13th, 2003, 12:08 PM
Registered User
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 5aTaN
Default

LOL... Hello again... Need more help

Not too familiar with Javascript - Any idea how to change the ACTION section of the form when the submit button is preSsed then?


Thanx.

Si






Similar Threads
Thread Thread Starter Forum Replies Last Post
VB 2005 question, binary to text file conversion pitcher General .NET 0 September 24th, 2007 07:45 PM
Binary Search on a text file scoobie Pro Java 1 August 25th, 2006 12:43 AM
Opening Text file in Binary mode for reading lawsoncobol Access VBA 1 August 3rd, 2006 04:01 AM
leaving blank text box in form when inserting data saif44 ASP.NET 2.0 Professional 1 March 9th, 2006 07:29 AM
Reading from a text file and writing to a Binary 1 scott01 C++ Programming 0 July 28th, 2003 03:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.