Retrieving a query string from a <FORM ACTION> command

Paul Goodyear paul at gudge.demon.co.uk
Mon Jul 31 12:20:10 EDT 2000


Yep i'm a newbie here.

Been doing this stuff for about a month and it rocks. The thing is I wrote a
guestbook and for the last weeks it's been working fine. But all of a sudden
the text that is sent to my server from the web page in the comments text
input or textarea boxes are sent with +'s instead of spaces.

I have tried both action="get" and action="post" in the HTML code.

I have put the code below that does the grabbing:

HTML CODE:
---------------

<form method="get" action="/cgi-bin/guestbook.py">


PYTHON CODE:
-------------------

    import time, string, os

    print "Content-type: text/html\n\n"

    qs = os.environ['QUERY_STRING']
    t = string.split(qs, "?")
    tt = string.split(t[0], '&')
    NameString = string.split(tt[0], '=')
    EmailString = string.split(tt[1], '=')
    CommentString = string.split(tt[2], '=');

    TimeString = time.ctime(time.time())

    GuestList = open('cgi-bin/guestbook.txt')
    CurrentGuest = GuestList.readlines()
    GuestList.close()


    GuestList = open('cgi-bin/guestbook.txt', 'w')
    line = NameString[1] + ',' + EmailString[1] + ',' + CommentString[1] +
',' + TimeString + '\n'
    GuestList.write(line)
    GuestList.writelines(CurrentGuest)
    GuestList.close()

I'm taking the query string and placing all the fields into variables,
reading in the current entries and then writing them all out again.

But as I said and why I need help is that all the spaces are now been
replaced with + sysbols, which can I stress didn't do at first. I have
changed the code and put it back and it did just the same.

Please help.

email or post.





More information about the Python-list mailing list