in reply to Key/Value Problem

The problem is that if an item is not selected in a form, it is not sent through to the script, so the script has no way of knowing what it is missing. I would add a list of the fields to your script, and go through them, and put the value in from the form if it is there, and otherwise put just put a comma like you want.
                - Ant

Replies are listed 'Best First'.
Re: Re: Key/Value Problem
by aconite (Initiate) on Apr 19, 2001 at 18:23 UTC
    That makes sense to me, and I appreciate the input. Can you show me an example of how I would add a field list and then iterate through them, presumably with a foreach loop. Thanks
      Sure... make an array of names...
      @fields = ('required-name','age'); # etc etc etc foreach $sortedkeys (@sortedkeys) { $sortedkeys =~ s/^\d*\)\s*//; $sortedkeys =~ s/required-//; ($name, $answer) = split (/\|/, $sortedkeys); $form{$name} = $answer; } #so now all your data is in a hash, keyed off the name. foreach $field (@fields) { #check if form value exists, if yes, put form value in #$answer, otherwise put a comma? $answer = (exists $form{$field} ? $form{$field} : ','); print FORM "$field -- $answer\n"; }
      That make sense?
      They will print in the order you put @fields in.
                      - Ant
        Thanks so much for your insights. The code you propose makes sense, but whenI run it with my form, it doesn't seem to actally get any of the answers provided. I created the @fiels array using the names that I use in the form (i.e. 'name','01','02','03' etc....). In my form, I have about 20 different elements that are radio button choices, so for question 2 it might be something like:
        <input type="radio" name="02" value="a"> Required in my major </td> <td> <input type="radio" name="02" value="b"> Required, not in my major </td> <td> <input type="radio" name="02" value="c"> An Elective </td>
        When the user picks the third option (value="c"), then I want that to show up for the value of field (name) "02". If they don't choose any of the options, then it will be a comma. When I test the code you suggest, I get a comma for every answer, whether I selected anything or not. Any ideas? I really appreciate all the information as I wade through this.