Intranet Journal
The online resource for intranet professionals
<%
some code to process form
some more code
.
.
.
if code is successful then
Response.Redirect("form2.asp")
End If
%>
<html>
<form method="post" action="form.asp">
some form elements
some more form elements
</form>
</html>
This method is cleaner than setting form actions to different pages, allows for a wizard-style interface, easy form validation, and allows you to easily direct the user to incorrectly inputted form items.
Let's assume that content is already written and is in some text-compatible format. How do you get the file on the server? Well, there's two ways to do that. You can either:
1) Give all your writers FTP access so they can upload the file
themselves or
2) Build a web form
There are plusses and minuses to both methods. Both methods require special permissions: method 1 requires FTP write permissions, while the second method requires either the user to be logged onto the server or HTTP write permissions. Also, with the first method, the upload process must be done separately from the management steps, and you'll have to supply the management system with the exact file name later. The second method will (or at least should) supply you with the exact file name and can be part of the whole system.
If you decide to go the second route, you'll need either a COM object or some strong knowledge of HTML binary form submission. Two common COM objects used for uploading files are:
But these can be rather expensive. A wonderful free one that I've used before is:
There's a great tutorial here at 15 Seconds.com on how exactly to upload files, so I won't explain it now. If you're a clever programmer and know the nitty-gritty of HTML form submission, then you may be able to create an ASP script in place of the COM object.
If you decided to make your writers submit their articles into a web based form, then you don't need to know about those COM objects above (but aren't you glad you read it anyway?). Instead, have your writer type or cut-and-paste his article into a textarea element on a web form. Then simply use the file system object (check out 4GuysFromRolla.com for a great tutorial on the file system object) to write that file on the server.
Okay, so the file is up. Now what?
If you followed step 2 from above, your ASP script should know the file name. If not, you'll have to build an extra step to ask the user for the file name. Once you get it, you'll want to store that filename (and maybe the absolute directory the file is in) in the database, so you don't forget it. The following code will enter the filename into the database: (note that the SQL statement uses the table name we created above).
<!--#include virtual="/scripts/adovbs.inc" -->
<%
set connFileName = Server.CreateObject("ADODB.Connection")
set rstFileName =
Server.CreateObject("ADODB.Recordset")connArticles.Open"dsn=my_db;DATABASE=my_db"
strSQL = "SELECT * FROM tblFiles"
rstFileName.Open strSQL, connFileName, adOpenKeySet, adLockOptimistic
rstFileName.AddNew
rstFileName.FileName = "blah.html" <--- Substitute
actual file name here
rstFileName.Update
intID = rstFileName.UID
rstFileName.Close
set rstFileName = Nothing
connFileName.Close
set rstFileName = Nothing
%>
NOTE:
adOpenKeySet and adLockOptimistic are Visual Basic
constants. They
are not readily available to the ASP environment, meaning
that if
you try to use the code above, you'll probably receive an
error on
the rstFileName.Open line. You can do one
of two
things: either use the numeric values of those constants, ie,
adOpenKeySet=1, adLockOptimistic=2, etc (but who can
remember all
those values?); or include the file ADOVBS.INC in the page.
This
file is usually located in the scripts virtual directory of
the
web server. If not, hunt around, it's there somewhere.
|
Now you have a means to access the file later. Before you move on
though, you'll want to know which document to use in the next step.
Since the form on this page was self-referencing, you can't call a
Request.Form in the next step to figure out the ID number
of the document you just submitted. Instead, at the end of the of
redirect URL, attach a querystring with the ID number, using intID
that
we created above:
Response.Redirect("step2.asp?ID" & intID)
Now when you need the information in the next step, just do a
Request.Querystring("ID") and
you'll know which document you were working on in the previous step.