Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problem filling an html form

Reply
Thread Tools

Problem filling an html form

 
 
Guest
Posts: n/a
 
      01-13-2012
# 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?
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      01-13-2012
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?
 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      01-13-2012
On 13 Ιαν, 21:35, MRAB <(E-Mail Removed)> 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.
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      01-13-2012
On 13/01/2012 20:16, Νικόλαος Κούρας wrote:
> On 13 Ιαν, 21:35, MRAB<(E-Mail Removed)> 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.
 
Reply With Quote
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      01-13-2012
On 13 Ιαν, 23:13, MRAB <(E-Mail Removed)> wrote:
> On 13/01/2012 20:16, Νικόλαος Κούρας wrote:
>
>
>
>
>
>
>
>
>
> > On 13 Ιαν, 21:35, MRAB<(E-Mail Removed)> *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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract Text to HTML, Form Filling & Better PDF to Image Conversion sherazam Java 0 09-27-2011 11:36 AM
Refresh "parent" form after filling out child popUp form? Bob ASP .Net 1 08-31-2007 09:39 AM
Refresh "parent" form after filling out child popUp form? Bob ASP .Net 0 08-31-2007 09:06 AM
Online form filling problem Leo9 Computer Support 1 04-20-2005 05:53 PM
Filling in HttpWebRequest object with form data =?Utf-8?B?RXJpayBKZW5zZW4=?= ASP .Net 3 02-11-2004 11:44 PM



Advertisments