Professional Web Applications Themes

Survey Form Problem - Macromedia Dynamic HTML

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: <input type="radio" name="RadioGroup1" value="5">5 <input type="radio" name="RadioGroup1" value="4">4 <input type="radio" name="RadioGroup1" value="3">3 <input type="radio" name="RadioGroup1" value="2">2 <input type="radio" name="RadioGroup1" value="1">1 <input type="radio" name="RadioGroup1" value="na">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, ...

  1. #1

    Default Survey Form Problem

    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:

    <input type="radio" name="RadioGroup1" value="5">5
    <input type="radio" name="RadioGroup1" value="4">4
    <input type="radio" name="RadioGroup1" value="3">3
    <input type="radio" name="RadioGroup1" value="2">2
    <input type="radio" name="RadioGroup1" value="1">1
    <input type="radio" name="RadioGroup1" value="na">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.FileSystemObjec t")
    Set f=fso.OpenTextFile(Server.MapPath ("myfile.csv"), 8, True)
    f.WriteBlankLines(1)
    f.WriteLine "Date : " & CStr(Date)
    For Each field in Request.Form
    If field<>"filesave" And field<>"redirpage" Then
    f.WriteLine field & " : " & 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!

    bake01 Guest

  2. #2

    Default Re: Survey Form Problem

    bake01 wrote: 

    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 <input> 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/
    David Guest

  3. #3

    Default Re: 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.

    bake01 Guest

  4. #4

    Default Re: Survey Form Problem

    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:

    <input type="checkbox" name="checkbox2" value="Customer Service"
    id="checkbox2">
    Customer Service
    <input type="hidden" name="checkbox2a" value="0" id="checkbox" checked>

    bake01 Guest

  5. #5

    Default Re: Survey Form Problem

    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.

    bake01 Guest

Similar Threads

  1. survey form
    By GeorgeWS in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: May 20th, 01:11 AM
  2. Customer Survey form
    By Karen_Little in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: February 21st, 04:57 AM
  3. Survey On Submit Disable Form
    By Speegs in forum Dreamweaver AppDev
    Replies: 2
    Last Post: April 22nd, 10:30 PM
  4. problem with cookie for a survey
    By Marc Collin in forum PHP Development
    Replies: 1
    Last Post: May 24th, 07:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139