cgi, python and forms

Akhar akhar at videotron.ca
Mon Mar 6 18:55:32 EST 2000


When I use :
#!/usr/local/bin/python
import cgi
import MySQLdb
import string
I = "Content-type: text/html"
J = "<HTML><TITLE>ADMIN SITE </TITLE><BODY>"
print I
print
print J
try:
        try:
                form = cgi.FieldStorage()
                NField = form["nom"]
                SField = form["serial"]
    except (KeyError, TypeError):
                        print "ay t"
                        raise SystemExit
        try:
                N = NField.value
                S = SField.value
    if form.has_key('name'):
                if form['name'].value=='Search':
                        print '<FORM METHOD="POST"
ACTION="/cgi-bin/find.py">'
                        ASK = 'select * from item where nom like "%'+ N +
I get an error at the line:    if form.has_key('name'):
the debugger says:
bash-2.03# python admin.py
  File "admin.py", line 36
    if form.has_key('name'):
     ^
SyntaxError: invalid syntax
can you help??
Akhar
<k_mcdermott at my-deja.com> wrote in message
news:89oria$n6g$1 at nnrp1.deja.com...
> In article <2WPv4.367$H95.27613 at wagner.videotron.net>,
>   "Akhar" <akhar at videotron.ca> wrote:
> > I woud like to know how can I tell my python cgi script to
> differenciate
> > these two:
> > <P><INPUT TYPE="SUBMIT" VALUE="SEND"></P>
> > <P><INPUT TYPE="SUBMIT" VALUE="m"></P>
> > I am using the cgi module but can't find any info on these.
> >
>
> On a form I have the following:
> <INPUT TYPE="submit" NAME="Action" VALUE="Search"> and
>
> <INPUT TYPE="submit" NAME="Action" VALUE="Submit">
>
>
> To differentiate these I can use
>
> formData = cgi.FieldStorage()
> if formData.has_key('Action'):
>     if formData['Action'].value == 'Search':
>         displaySearch(formData)
>     if formData['Action'].value == 'Submit':
>         processEntry(formData)
> else:
>     displayEntryForm(formData)
>
> In Other words, I can pick up the form data or display the form for
> entry.
>
> These are generated with the following HTMLgen code:
>
> entryForm = BasicDocument(cgi=1)
>
> entryForm.append(.........) # various elements for the form
>
> entryForm.append(Input(value='Search', type='submit', name='Action'))
> entryForm.submit = Input(type='submit', value='Submit', name='Action')
>
> Try HTMLgen, it's great.
>
> Kevin
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.





More information about the Python-list mailing list