writing form contents to a file
Steve Holden
sholden at holdenweb.com
Sat May 3 14:31:23 EDT 2003
"Psybar Phreak" <gotyoubacktoo at yahoo.com> wrote ...
> hi again - big thanks to everyone who helped out with my last question
about
> reading from a file, but now i have a simlar prob, only the other way
> around - WRITING to a file, only a little more complicated
>
> i have a basic HTML page that has two form elemets (just text boxes - name
> and password), and what i want to do, is write them to a file in the form
> username
> password
>
> the two text boxes on the web page are label usernameField and
passwordField
>
> not quite sure where to start on this one, so any helpw ould be greatly
> appreciated
>
> thanks all!
>
Load the following script on your server where it can be executed as a CGI,
and make it the ACTION attribute of your <FORM ...> in the HTML page the
user has to fill out:
import cgi
form = cgi.FieldStorage()
user = form["username"].value
pswd = form["password"].value
outfile = file("/tmp/somename.txt", "w")
outfile.write("%s\n%s\n" % (user, pswd)
# or print >> outfile, user, '\n', pswd
outfile.close
print """Content-Type: text\html
<html><head><title>Woo Hoo!</title></head>
<body><p>Just wrote the file</p></body></html>
"""
This is untested code, and worth just what you paid for it :-)
regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
More information about the Python-list
mailing list