Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18928 > unrolled thread
| Started by | Νικόλαος Κούρας <nikos.kouras@gmail.com> |
|---|---|
| First post | 2012-01-13 09:02 -0800 |
| Last post | 2012-01-13 17:20 -0800 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.python
Problem filling an html form Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-13 09:02 -0800
Re: Problem filling an html form MRAB <python@mrabarnett.plus.com> - 2012-01-13 19:35 +0000
Re: Problem filling an html form Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-13 12:16 -0800
Re: Problem filling an html form MRAB <python@mrabarnett.plus.com> - 2012-01-13 21:13 +0000
Re: Problem filling an html form Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-13 13:30 -0800
Re: Problem filling an html form Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-13 17:20 -0800
| From | Νικόλαος Κούρας <nikos.kouras@gmail.com> |
|---|---|
| Date | 2012-01-13 09:02 -0800 |
| Subject | Problem filling an html form |
| Message-ID | <adffac88-65e7-4057-b7b0-956fde49a8bd@p42g2000vbt.googlegroups.com> |
# 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?
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-01-13 19:35 +0000 |
| Message-ID | <mailman.4724.1326483339.27778.python-list@python.org> |
| In reply to | #18928 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Νικόλαος Κούρας <nikos.kouras@gmail.com> |
|---|---|
| Date | 2012-01-13 12:16 -0800 |
| Message-ID | <41330576-e597-4e7a-82b1-1aeca9434b00@n6g2000vbz.googlegroups.com> |
| In reply to | #18936 |
On 13 Ιαν, 21:35, MRAB <pyt...@mrabarnett.plus.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-01-13 21:13 +0000 |
| Message-ID | <mailman.4731.1326489211.27778.python-list@python.org> |
| In reply to | #18941 |
On 13/01/2012 20:16, Νικόλαος Κούρας wrote:
> On 13 Ιαν, 21:35, MRAB<pyt...@mrabarnett.plus.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Νικόλαος Κούρας <nikos.kouras@gmail.com> |
|---|---|
| Date | 2012-01-13 13:30 -0800 |
| Message-ID | <a909952a-6197-48f8-a131-45c9bd1fd579@o12g2000vbd.googlegroups.com> |
| In reply to | #18946 |
On 13 Ιαν, 23:13, MRAB <pyt...@mrabarnett.plus.com> wrote:
> On 13/01/2012 20:16, Νικόλαος Κούρας wrote:
>
>
>
>
>
>
>
>
>
> > On 13 Ιαν, 21:35, MRAB<pyt...@mrabarnett.plus.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Νικόλαος Κούρας <nikos.kouras@gmail.com> |
|---|---|
| Date | 2012-01-13 17:20 -0800 |
| Message-ID | <d70b3668-602a-4760-a0bc-e2725285b743@i25g2000vbt.googlegroups.com> |
| In reply to | #18949 |
On 13 Ιαν, 23:30, Νικόλαος Κούρας <nikos.kou...@gmail.com> wrote:
> On 13 Ιαν, 23:13, MRAB <pyt...@mrabarnett.plus.com> wrote:
>
>
>
>
>
>
>
>
>
> > On 13/01/2012 20:16, Νικόλαος Κούρας wrote:
>
> > > On 13 Ιαν, 21:35, MRAB<pyt...@mrabarnett.plus.com> 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.
I've made some progress,
here is a part of index.html:
=====================================================================================
<form method="post" action="..\index.html">
<input type="text" name="mail" value="To mail σου?"><br>
<textarea name="comment" cols="30" rows="5">
Ρωτήστε σχετικά...
</textarea><br>
<input type="hidden" name="page" value="index.html">
<input type="hidden" name="ok" value="pressed">
<input type="submit" value="ΟΚ">
</form>
=====================================================================================
and here is a part of counter.py:
=====================================================================================
# insert guest comments into database if form was submitted
if ('@' in mail) and ("Ρωτήστε σχετικά..." not in comment):
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)
elif (ok == 'pressed') and ('@' not in mail or comment == ''):
print ( "<h2><font color=red>Συμπλήρωσε σωστά το mail σου και δώσε
το σχολιασμό σου!" )
sys.exit(0)
=====================================================================================
Is there a way to check 'mail' and 'comment' variables for emptyness
and '@' not in mail
without passing the value of 'pressed' to the hidden field 'ok'?
Also are the above html statements the same?
<form method="post" action="..\index.html">
<form method="post" action=""> <= Does it implies to run itself?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web