Problem filling an html form

Discussion in 'Python' started by Íéêüëáïò Êïýñáò, Jan 13, 2012.

  1. # 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?
     
    Íéêüëáïò Êïýñáò, Jan 13, 2012
    #1
    1. Advertising

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

    MRAB Guest

    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?
     
    MRAB, Jan 13, 2012
    #2
    1. Advertising

  3. On 13 Ιαν, 21:35, MRAB <> wrote:
    > 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.
     
    Íéêüëáïò Êïýñáò, Jan 13, 2012
    #3
  4. Íéêüëáïò Êïýñáò

    MRAB Guest

    On 13/01/2012 20:16, Îικόλαος ΚοÏÏας wrote:
    > On 13 Ιαν, 21:35, MRAB<> wrote:
    >> 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.
     
    MRAB, Jan 13, 2012
    #4
  5. On 13 Ιαν, 23:13, MRAB <> wrote:
    > On 13/01/2012 20:16, Îικόλαος ΚοÏÏας wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On 13 Ιαν, 21:35, MRAB<>  wrote:
    > >>  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.
     
    Îικόλαος ΚοÏÏας, Jan 13, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    1
    Views:
    656
  2. Bob
    Replies:
    0
    Views:
    490
  3. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    121
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  4. MRAB
    Replies:
    0
    Views:
    119
Loading...

Share This Page