Hi.
I am writing up my own web form. I'm a bit of a newb, and read up many
different how-tos and examples and documentaion. I finally had it
working just great until I decided that I wanted to add some extra
logic because there's one form that submits a particular type of
information. a little extra validation, and the creation of a list of
the values to be mailed in to the site manager.
The code below is where I am going wrong (edited for brevity):
form=cgi.FieldStorage()
rev_fields = { "param1":None, "param3":None, "param6":None,
"param5":None, "param8":None, "param9":None, "param10":None,
"param11":None }
# Everything worked until I added the following if statement:
if form.has_key("param8"): # Only one form has this
param8 = form.getvalue("param8")
if param8 == 0: # 0 is the default value
print "Content-type: text/html"
debug("You must give the item a rating")
for field in form.keys():
value = form[field].value
if rev_fields.has_key(field):
rev_fields[field] = value
for key in rev_fields:
if rev_fields[key] == None:
print "Content-type: text/html"
debug("All fields must be filled in. Please check your %s
submission." % key)
else:
#feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" %
(form["param1"].value, form["param3"].value, form["param6"].
value, form["param5"].value, form["param8"].value,
form["param9"].value, form["param10"].value, form["param11"].value)
#feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" %
(form.getvalue("param1"), form.getvalue("param3"), form.getvalue(
"param6"), form.getvalue("param5"), form.getvalue("param8"),
form.getvalue("param9"), form.getvalue("param10"),
form.getvalue("param11"))
feedback = ("%s, %s, %s, %s, %s, %s" %
(rev_fields["param1"], rev_fields["param3"], rev_fields["param6"],
rev_fields["param5"], rev_fields["param8"], rev_fields["param9"],
rev_fields["param10"], rev_fields["param11"])
#feedback = form[ "score" ].value
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n"
%
(rev_fields["param2"], rev_fields["param7"], rev_fields["param3"],
rev_fields["param6"]))
If I comment out the 'else:' logic, it works great. But then I don't
get a list called feedback containing all teh bits I want, The error I
get is really strange, too:
[Mon Aug 15 05:54:58 2005] [error] [client 60.224.106.116] Premature
end of script headers: /var/www/users/senta/html/gobooks/cgi/form.py
File "/var/www/users/senta/html/gobooks/cgi/form.py", line 99
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback:
%s\r\n\r\n" %
^
SyntaxError: invalid syntax
Just a simple assignation.... I did think it might have been an
indentation error, but I changed that around and got a message telling
me about an indentation problem, which this doesn't do.
I have tried several different ways to assign the values, as you can
see by the commented out lines. Tried getting the values directly from
teh form, and also from the validated rev_fields dictionary. I'd be
extremely grateful to anyone who helps me through this.
TIA
Googleboy 1 2439
googleboy wrote: Hi.
I am writing up my own web form. I'm a bit of a newb, and read up many different how-tos and examples and documentaion. I finally had it working just great until I decided that I wanted to add some extra logic because there's one form that submits a particular type of information. a little extra validation, and the creation of a list of the values to be mailed in to the site manager.
The code below is where I am going wrong (edited for brevity):
form=cgi.FieldStorage()
rev_fields = { "param1":None, "param3":None, "param6":None, "param5":None, "param8":None, "param9":None, "param10":None, "param11":None }
# Everything worked until I added the following if statement:
if form.has_key("param8"): # Only one form has this param8 = form.getvalue("param8") if param8 == 0: # 0 is the default value print "Content-type: text/html" debug("You must give the item a rating") for field in form.keys(): value = form[field].value if rev_fields.has_key(field): rev_fields[field] = value for key in rev_fields: if rev_fields[key] == None: print "Content-type: text/html" debug("All fields must be filled in. Please check your %s submission." % key) else: #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % (form["param1"].value, form["param3"].value, form["param6"]. value, form["param5"].value, form["param8"].value, form["param9"].value, form["param10"].value, form["param11"].value) #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % (form.getvalue("param1"), form.getvalue("param3"), form.getvalue( "param6"), form.getvalue("param5"), form.getvalue("param8"), form.getvalue("param9"), form.getvalue("param10"), form.getvalue("param11")) feedback = ("%s, %s, %s, %s, %s, %s" % (rev_fields["param1"], rev_fields["param3"], rev_fields["param6"], rev_fields["param5"], rev_fields["param8"], rev_fields["param9"], rev_fields["param10"], rev_fields["param11"])
I believe you missed a closing parenthesis, which is why you are getting
the syntax error - the scanner has to look at the next source line
because it expects it to continue the unclosed expression. That's why
you are getting confused.
#feedback = form[ "score" ].value
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n" % (rev_fields["param2"], rev_fields["param7"], rev_fields["param3"], rev_fields["param6"]))
Since rev_fields is a dictionary, it would be easier to write this as
msg = "From %(param2)s\r\nTo: %(param7)\r\nSubject: %(param3)s\r\n\r\n
Feedback: %(param6)s\r\n\r\n" % rev_fields
module any text wrapping the mailstream might have done to the above
single line. If I comment out the 'else:' logic, it works great. But then I don't get a list called feedback containing all teh bits I want, The error I get is really strange, too:
[Mon Aug 15 05:54:58 2005] [error] [client 60.224.106.116] Premature end of script headers: /var/www/users/senta/html/gobooks/cgi/form.py File "/var/www/users/senta/html/gobooks/cgi/form.py", line 99 msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n" % ^ SyntaxError: invalid syntax
Just a simple assignation.... I did think it might have been an indentation error, but I changed that around and got a message telling me about an indentation problem, which this doesn't do.
I have tried several different ways to assign the values, as you can see by the commented out lines. Tried getting the values directly from teh form, and also from the validated rev_fields dictionary. I'd be extremely grateful to anyone who helps me through this.
TIA
Googleboy
Hope this helps.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stefan Richter |
last post by:
Hi, after coding for days on stupid form validations -
Like:
strings (min / max length), numbers(min / max value), money(min / max
value), postcodes(min / max value), telefon numbers,
email...
|
by: Suzanne Murray |
last post by:
Hi,
I am trying to provide some simple validation using Javascript on my
form.
However at times the validation works and at others it doesn't and
submits the form without any warnings even...
|
by: Steve Benson |
last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and
got the job of adapting existing code. In the page below, everything works
until I added the function checkIt() to...
|
by: billa |
last post by:
I wish to carry out standard form validation (i.e. is it a date?, is
there a value in the field, is it a number) using the onBlur event
rather than the onSubmit event. This (of course) leads to...
|
by: Hosh |
last post by:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate...
|
by: Chris |
last post by:
Hi,
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it...
|
by: Phil Latio |
last post by:
I've been creating an application over the last few weeks and generally
pleased with what I have produced but one area is irritating me, form
validation.
At the moment the forms are simply...
|
by: gweasel |
last post by:
What is the best way to apply a Validation Rule - or rather, where is
the best place to put it? Is there an advantage to putting it on the
field in the table vs setting the validation rule on the...
|
by: Gustaf |
last post by:
I've been working on a membership form for a while, and find it very
tedious to get an acceptable level of form validation. A web search for
solutions revealed some home-brewed solutions, such as...
|
by: smk17 |
last post by:
I've spent the last few minutes searching for this question and I
found an answer, but it wasn't quite what the client wanted.
I have a simple online form where the user needs to fill out five...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |