Problem filling an html form

  • Thread starter Íéêüëáïò Êïýñáò
  • Start date
Í

Íéêüëáïò Êïýñáò

# get some enviromental values
form = cgi.FieldStorage()
mail = form.getvalue('mail') or ''
comment = form.getvalue('comment') or ''

# insert guest comments into database if form was submitted
if '@' in mail and comment not in ("ÑùôÞóôå ìå ó÷åôéêÜ..."):
try:
cursor.execute( '''INSERT INTO users(mail, comment) VALUES(%s,
%s)''', (mail, comment) )
except MySQLdb.Error, e:
print ( "Error %d: %s" % (e.args[0], e.args[1]) )

print ( "<h2><font color=blue>Åõ÷áñéóôþ ãéá ôçí åñþôçóç! Èá óáò
áðáíôÞóù ôï óõíôïìüôåñï äõíáôü!" )
sys.exit(0)
else:
print ( "<h2><font color=red>ÓõìðëÞñùóå óùóôÜ ôï mail óïõ êáé äþóå
ôï ó÷ïëéáóìü óïõ!" )
sys.exit(0)
==============================================

In my webpage here http://superhost.gr/hosting.html i ask the users
mail and comment in a html form.

No matter what info the user gives after he submits the form, nothing
else happens instead of reloading the page itself while what i want
the code to do is to enter the if structure and display the
appropriate message, depending if the user entered data in the imput
box or not.

Am i missing something here?
 
M

MRAB

# get some enviromental values
form = cgi.FieldStorage()
mail = form.getvalue('mail') or ''
comment = form.getvalue('comment') or ''

# insert guest comments into database if form was submitted
if '@' in mail and comment not in ("ÑùôÞóôå ìå ó÷åôéêÜ..."):

[snip]

Do you really want to look for the comment in that string instead of
looking for that string in the comment?
 
Í

Íéêüëáïò Êïýñáò

# get some enviromental values
form = cgi.FieldStorage()
mail = form.getvalue('mail') or ''
comment = form.getvalue('comment') or ''
   # insert guest comments into database if form was submitted
   if '@' in mail and comment not in ("ÑùôÞóôå ìå ó÷åôéêÜ..."):

[snip]

Do you really want to look for the comment in that string instead of
looking for that string in the comment?

What do you mean?

I just want to check that the user hasnt pressed the submit button
leaving the default values with the input comment box.

Iam not sure what you mean.
 
M

MRAB

# get some enviromental values
form = cgi.FieldStorage()
mail = form.getvalue('mail') or ''
comment = form.getvalue('comment') or ''
# insert guest comments into database if form was submitted
if '@' in mail and comment not in ("ÑùôÞóôå ìå ó÷åôéêÜ..."):

[snip]

Do you really want to look for the comment in that string instead of
looking for that string in the comment?

What do you mean?

I just want to check that the user hasnt pressed the submit button
leaving the default values with the input comment box.

Iam not sure what you mean.

In the first part of the condition you're asking:

'@' in mail

which is OK, but in the second part of the condition you're asking:

comment not in ("Ρωτήστε με σχετικά...")

which I think should be:

"Ρωτήστε με σχετικά..." not in comment

Incidentally, it looks to me like you're using Python 2, in which case
it's probably a good idea to use Unicode, so that would be:

u"Ρωτήστε με σχετικά..." not in comment

and so forth.
 
Î

Îικόλαος ΚοÏÏας

 On 13/01/2012 17:02, Ãéêüëáïò Êïýñáò wrote:
 >  # get some enviromental values
 >  form = cgi.FieldStorage()
 >  mail = form.getvalue('mail') or ''
 >  comment = form.getvalue('comment') or ''
 >      # insert guest comments into database if form was submitted
 >      if '@' in mail and comment not in ("ÑùôÞóôå ìå ó÷åôéêÜ..."):
 [snip]
 Do you really want to look for the comment in that string instead of
 looking for that string in the comment?
What do you mean?
I just want to check that the user hasnt pressed the submit button
leaving the default values with the input comment box.
Iam not sure what you mean.

In the first part of the condition you're asking:

     '@' in mail

which is OK, but in the second part of the condition you're asking:

     comment not in ("Ρωτήστε με σχετικά...")

which I think should be:

     "Ρωτήστε με σχετικά..." not in comment

Incidentally, it looks to me like you're using Python 2, in which case
it's probably a good idea to use Unicode, so that would be:

     u"Ρωτήστε με σχετικά..." not in comment

and so forth.

Ah yes i have had them reversed!

I corrected that now but still if the user submits the form by not
entering any input all the program does is reloads itself.

So the question now is why the program flow doesn't enter the if code
block since its conditions are met?

ps. http//superhost.gr/hosting.html is now http//superhost.gr/
directly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top