Help - Search - Members - Calendar
Full Version: html form
ieXbeta Board > Tech > Developer Center
XP_2600
guys i need to something so simple, i have to attach a site in IIS here just collecting three pieces of information employee name and employee ID and last name, i want to html form do it and save the data in a text file near the html code, i have windows 2003 and IIS running i have frontpage exctentions running but i dont have PhP and i cant install it, so any ideas ? please help.
DangerousDave86
What about ASP(.Net)?
I don't know what FP extensions are capable of. In FrontPage you can design forms that link to databases (Access). That may work.
Dutch2005
QUOTE(XP_2600 @ Nov 23 2006, 15:43) *

guys i need to something so simple, i have to attach a site in IIS here just collecting three pieces of information employee name and employee ID and last name, i want to html form do it and save the data in a text file near the html code, i have windows 2003 and IIS running i have frontpage exctentions running but i dont have PhP and i cant install it, so any ideas ? please help.



how bout some of those php--> asp convertors? (if php is no option)
Phonics Monkey
Why can't you install PHP? Access/Permissions issue? If it's just a setup/configuration issue, I can help you with that.
quantumAlpha
i dont reccommend using a PHP/ASP converter, they dont work well. For doing what you are, something so simple, just use ASP as it's built in and couldnt get any easier.
DangerousDave86
You could pretty much put together a script to do this from any ASP example on the web. www.w3schools.com/asp/ will surely have the two examples you need. Writing to files and collecting use input.
XP_2600
I gave www.w3schools.com/asp/ a try but for some reason its didnt work.
Phonics Monkey
QUOTE(XP_2600 @ Nov 25 2006, 03:46) *

I gave www.w3schools.com/asp/ a try but for some reason its didnt work.

Write permissions get tricky fast with IIS, have you tried a simple asp script to make sure it has execute permissions on the site (there are no global settings) in question?

Gut the script so it only tries to create the file, to verify you can write to the drive. If not make sure the IGA has the necessary NTFS permissions for the target.

The visitor IP log file (Only!) on my server uses the NTFS full control perms for the IGA to allow the index page's PHP script to write to/update the file, even tho site level write access is disabled.
XP_2600
Phonics Monkey, if you can make basic one for me ill appreciate it so much, i dont have enough time and im in involved in manything , i need html page with two field employee name and employee id and i i want it to save to any file, im using windows 2003 IIS v6 and i have ASP extensions enabled, if you can help me with a code it will be great, thanks so much.
Phonics Monkey
Greetings
I'm a bit low on free time myself... biggrin.gif ...So I didn't do any cleaning on this code to hack it down to the bare essentials, but I know it works.


The below code sample (Which I googled for) shows how to do the basic file operations (read/write/create/delete) in asp. It will (/should) work on your server with only 2 changes if the page is located in site root.

1. You need to create a folder called data in the site root (which it writes the file to).

2. You need to grant the Full Control NTFS permission to the IGA for the Data folder only.


Obviously item 2 is bad form for proper server security, but that can be dialed it later after you get what you want working to work. I as I recall you already know about the whole file permission game so there is no point on my lecturing you on that. wink.gif

CODE
<%@ LANGUAGE="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<% '***************************************************************************
   '* ASP File Operations                                                     *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 1999, 2000 by Mike Hall.                                      *
   '* Please see http://www.brainjar.com for documentation and terms of use.  *
   '***************************************************************************
  
   'Set file I/O constants.

   Const ForReading   = 1
   Const ForWriting   = 2
   Const ForAppending = 8

   'Map the file name to the physical path on the server.

   filename = "temp.txt"
   path = Server.MapPath(".") & "\data\" & filename

   'Get requested operation, if any.

   operation = Request.Form("operation") %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ASP File Operations Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/common/default.css" />
</head>
<body>

<div id="demoBox">

<h3>ASP File Operations Demo</h3>

<p>Select a file operation below, the action will be performed against a text
file named '<a href="data/<% = filename %>"><% = filename %></a>' and the
contents will be displayed.</p>

<p>Note that the file may be suddenly changed or deleted if any one else
happens to be performing operations against it.</p>

</div>

<form action="<% = Request.ServerVariables("SCRIPT_NAME") %>" method="post">
<p>
  <input name="operation" type="radio" value="create" /> Create
  <input name="operation" type="radio" value="delete" /> Delete
  <input name="operation" type="radio" value="read" checked="checked" /> Read
  <input name="operation" type="radio" value="write" /> Write
  <input name="operation" type="radio" value="append" /> Append
</p>
<p>
  <input type="submit" value="Submit" />
  <input type="reset" value="Reset" />
</p>
</form>

<p>
<% 'Perform the request operation.

   if operation = "create" then
     CreateFile(path)
     ReadFile(path)
   elseif operation = "delete" then
     call DeleteFile(path)
   elseif operation = "read" then
     call ReadFile(path)
   elseif operation = "write" then
     call WriteFile(path)
     ReadFile(path)
   elseif operation = "append" then
     call AppendFile(path)
     ReadFile(path)
   end if %>
</p>

</body>
</html>

<% sub CreateFile(path)

     dim fs, file

     Response.Write("<b>CreateFile:</b><br>")

     set fs = CreateObject("Scripting.FileSystemObject")

     'If the file already exists give an error message.

     if fs.FileExists(path) then
       Response.Write("File " & filename & " already exists, create aborted.<br>" & vbCrLf)

     'Otherwise create it and write some data to it.

     else
       Response.Write("Creating " & filename & ".<br>")
       set file = fs.CreateTextFile(path)
       Response.Write("Writing data to " & filename & ".<br>")
       file.WriteLine("Line 1 added " & Now() & ".")
       file.WriteLine("Line 2 added " & Now() & ".")
       file.WriteLine("Line 3 added " & Now() & ".")
       file.WriteLine("Line 4 added " & Now() & ".")
       file.WriteLine("Line 5 added " & Now() & ".")
       file.Close()
     end if

   end sub

   sub DeleteFile(path)

     dim fs, file

     Response.Write("<b>DeleteFile:</b><br>")

     set fs = CreateObject("Scripting.FileSystemObject")

     'If the file doesn't exist give an error message.

     if not fs.FileExists(path) then
       Response.Write("File " & filename & " does not exist.<br>")

     'Otherwise delete it.

     else
       Response.Write("Deleting " & filename & ".<br>")
       fs.DeleteFile(path)
     end if

   end sub

   sub ReadFile(path)

     dim fs, file

     Response.Write("<b>ReadFile:</b><br>")

     set fs = CreateObject("Scripting.FileSystemObject")

     'If the file doesn't exist give an error message.

     if not fs.FileExists(path) then
       Response.Write("File " & filename & " does not exist, read aborted.<br>")


     'Otherwise, open it and display the contents.

     else
       set file = fs.OpenTextFile(path, ForReading)
       Response.Write("Reading " & filename & ".<br>")
       Response.Write("<pre>")
       do while not file.AtEndOfStream
         Response.Write(file.ReadLine & vbCrLf)
       loop
       Response.Write("</pre>")
       file.Close()
     end if

   end sub

   sub WriteFile(path)

     dim fs, file

     Response.Write("<b>WriteFile:</b><br>")

     set fs = CreateObject("Scripting.FileSystemObject")

     'If the file doesn't exist give an error message.

     if not fs.FileExists(path) then
       Response.Write("File " & filename & " does not exist, write aborted.<br>")

     'Otherwise, overwrite the contents.

     else
       set file = fs.OpenTextFile(path, ForWriting)
       Response.Write("Rewritng file " & filename & ".<br>")
       file.WriteLine("Rewriting file with line 1 added " & Now() & ".")
       file.WriteLine("Rewriting file with line 2 added " & Now() & ".")
       file.WriteLine("Rewriting file with line 3 added " & Now() & ".")
       file.Close()
     end if

   end sub

   sub AppendFile(path)

     dim fs, file

     Response.Write("<b>AppendFile:</b><br>")

     set fs = CreateObject("Scripting.FileSystemObject")

     'If the file exists, check its size and exit if it exceeds 500K.

     if fs.FileExists(path) then
       set file = fs.GetFile(path)
       if file.size > 300 then
         Response.Write("Size limit exceeded for file " & filename & ", append aborted.<br>")
         exit sub
       end if

     'If the file doesn't exists, give a informational message.

     else
       Response.Write("File " & filename & " does not exist, will create.<br>")
     end if

     'Open or create the file as needed and append a line to it.

     Response.Write("Appending line to " & filename & ".<br>")
     set file = fs.OpenTextFile(path, ForAppending, true)
     file.WriteLine("New line added " & Now() & ".")
     file.Close()

   end sub %>



I'll keep this as a running sample on my intranet webserver so we can work on tweaking it to your needs, after you get it to run (which I'm assuming or at least hoping it will).
XP_2600
Thanks so much PM for this code.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.