I have a survey form whose results post back to a .CSV form.
My problem is that if someone does not answer all of the questions
(and none are mandatory), the answers end up in the wrong columns.
Questions are answered such as:
%26lt;input type=''radio'' name=''RadioGroup1'' value=''5''%26gt;5
%26lt;input type=''radio'' name=''RadioGroup1'' value=''4''%26gt;4
%26lt;input type=''radio'' name=''RadioGroup1'' value=''3''%26gt;3
%26lt;input type=''radio'' name=''RadioGroup1'' value=''2''%26gt;2
%26lt;input type=''radio'' name=''RadioGroup1'' value=''1''%26gt;1
%26lt;input type=''radio'' name=''RadioGroup1'' value=''na''%26gt;na
Also on the form are checkboxes and a text field. What do I
need to add that will report a blank answer if a radio or checkbox
is not answered? If it helps, following is the code for the form
that processes the answers:
Dim datafile, redirectpage
datafile=Request.Form(''filesave'')
redirectpage=Request.Form(''redirpage'')
Dim fso, f
Set fso=Server.CreateObject(''Scripting.FileSystemObject'')
Set f=fso.OpenTextFile(Server.MapPath (''myfile.csv''), 8,
True)
f.WriteBlankLines(1)
f.WriteLine ''Date : '' %26amp; CStr(Date)
For Each field in Request.Form
If field%26lt;%26gt;''filesave'' And field%26lt;%26gt;''redirpage'' Then
f.WriteLine field %26amp; '' : '' %26amp; Request.Form(field)
End If
Next
f.WriteBlankLines(1)
f.Close
Set f=Nothing
Set fso=Nothing
Response.Redirect ''thankyou.asp''
Thanks in advance for your help on this!Survey Form Problem
bake01 wrote:
%26gt; I have a survey form whose results post back to a .CSV
form. My problem is
%26gt; that if someone does not answer all of the questions
(and none are mandatory),
%26gt; the answers end up in the wrong columns.
Your problem is due to the way radio buttons and checkboxes
work. If
nothing is selected in a radio button group or a checkbox is
left
unselected, it doesn't appear in the form data. So, if the
user selects
nothing in RadioGroup1, RadioGroup1 doesn't have a blank
value, nothing
is passed to your script.
One approach with radio buttons is to set ''No answer'' as the
default by
inserting checked=''checked'' in the %26lt;input%26gt; tag. That
way, you will
always get a value from a radio button group: the default ''no
answer'' or
whatever the user selects.
You can't do that with checkboxes. Basically, you need to
check your
form data array to find if there's a value for each checkbox.
If any
checkbox is missing, you need to insert a ''no answer'' value
in the array
at the appropriate point. I could write a script to do this
in PHP, but
not VB Script. In pseudocode, it would go something like
this:
if (length of form array is not equal to maximum possible
answers) {
if (checkbox A not in form array) {
insert '' in array at appropriate position
}
if (checkbox B not in form array) {
insert '' in array at appropriate position
}
process form data as before
--
David Powers, Adobe Community Expert
Author, ''The Essential Guide to Dreamweaver CS3'' (friends of
ED)
Author, ''PHP Solutions'' (friends of ED)
http://foundationphp.com/
Survey Form Problem
The pre-selected radio button worked perfectly - thanks. It's
going to take some trial and error to work through the script for
the checkboxes, though. If anyone has a vbscript fix, I would
appreciate it. Thanks for your help, David.
Problem solved. My solution was to create a corresponding
hidden checkbox for each checkbox on the form with value = 0. So,
if somebody does not check a box, I get a ''checkbox1a=0'' on my
postback form keeping the database fields in order. Here's the
code:
%26lt;input type=''checkbox'' name=''checkbox2'' value=''Customer
Service'' id=''checkbox2''%26gt;
Customer Service
%26lt;input type=''hidden'' name=''checkbox2a'' value=''0''
id=''checkbox'' checked%26gt;
Oops - that did not work so well. What happens with the above
code is that now if somebody does select checkboxes, it reports
BOTH the checked box AND the hidden box, therefor putting data into
incorrect fields on the postback form.
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment