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.FieldS torage()
rev_fields = { "param1":No ne, "param3":No ne, "param6":No ne,
"param5":No ne, "param8":No ne, "param9":No ne, "param10":N one,
"param11":N one }
# Everything worked until I added the following if statement:
if form.has_key("p aram8"): # 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 2451
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.FieldS torage()
rev_fields = { "param1":No ne, "param3":No ne, "param6":No ne, "param5":No ne, "param8":No ne, "param9":No ne, "param10":N one, "param11":N one }
# Everything worked until I added the following if statement:
if form.has_key("p aram8"): # 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\nT o: %(param7)\r\nSu bject: %(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 adresses and so on.
I thought it might be a better way to programm an automated, dynamic
form validation that works for all kinds of fields, shows the
necessary error messages and highlights the coresponding form fields.
|
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 though it contains invalid
values. And sometimes it displays the warnings and submits the form!
I'm really confused and don't know what else I can do (I want to provide
the validation server-side)
|
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 validate which radio button was
clicked and what was in a textfield. The form is an attendance checking page
for a cyber charter school. What I'm trying to accomplish is that if a
parent marks the student present, there should not be anything in the...
|
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 problems when
cancelling an edit as leaving a field to press the cancel button will
trigger the onBlur event and therefore the field validation. Is there
any way to know the destination field / button that caused the onBlur
event? In Ingres ABF/W4GL...
|
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 individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely...
| |
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 appears that the data goes straight to the
processing page, rather than the javascript seeing if data is missing and
popping up an alert. I thought it may be because much of the form is
populated with data from the db (lists, etc.), but when I leave...
|
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 static html templates and the form input
is checked using a validation class. Basically each form field is checked,
every error is stored to an array and at the end of checking of the complete
form, the array is output neatly at the top of the form.
...
|
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 form the
control is on?
Basically I have a number of controls in a form that are required, and
to check it I am setting the Validation Rule to "<>"IsNull" so that
when the user tries to tab through/click out of a required area
without entering...
|
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 these:
http://simonwillison.net/2003/Jun/17/theHolyGrail/
http://samuelsjoberg.com/archive/2004/11/form-validation-on-client-and-server
Quoting from the first link, this is my idea of what form validation is
like from the user's perspective:
|
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
fields out of nine. The other four are already there and filled out
for the user. When they hit submit, all data is sent to us.
But, if they desire (for whatever reason) the user can possibly delete
what is already there and fill in something...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |