Re: problem with ILLEGALVAL in 3.2.2?

Joel Palmius <[email protected]> Sat, 19 Mar 2005 11:19:27 +0100 (CET)
Newsgroups gmane.comp.apache.mod-survey.general
Message-ID <[email protected]>
Ok, attached to this mail is an example of how to modify a submitted 
value. Beware that there might be some unforeseen consequences in some 
data exports (nothing critical, but some captions might end up in the 
wrong place around the multichoice question).

   // Joel


On Sat, 19 Mar 2005, Joel Palmius wrote:

> This is possible to make happen with a submit perl snippet though. Let me 
> think a bit about it and I'll be back with an example.
>
>  // Joel
>
>
> On Fri, 18 Mar 2005, Todd Slater wrote:
>
>>  I see; I had never tried this before but the person I'm writing the
>>  survey for expected that a person might not select any of the choices,
>>  but did not want to put a "none of the above" option for fear of getting
>>  selections *and* none of the above, thus invalidating the answer. At the
>>  same time, she wants a value other than null if nothing is selected.
>> 
>>  Todd
>> 
>>  On Fri, Mar 18, 2005 at 11:23:26PM +0100, Joel Palmius wrote:
>> >  No, ILLEGALVAL does not have any function in a multichoice. The result 
>> >  of
>> >  a multichoice is a comma-delimited list of checked values, and in
>> >  consequence a list of no elements if no value was checked. This is
>> >  considered a legal value.
>> > 
>> >  This is at least the intended behavior. Has the behavior changed from
>> >  earlier versions?
>> > 
>> >  // Joel
>> > 
>> > 
>> >  On Fri, 18 Mar 2005, Todd Slater wrote:
>> > 
>> > >  I'd like to set up a question that a user doesn't have to answer, and 
>> > >  if
>> > >  they don't answer it I'd like the value to be "7". Here's the item in
>> > >  question, but when I look at the data the value for it is blank/null. 
>> > >  Is
>> > >  there anything wrong with my syntax?
>> > > 
>> > >  <CHOICE MULTI="yes" NAME="retplan" MUSTANSWER="no"
>> > >  ILLEGALVAL="7" CAPTION="Have you completed or are you actively 
>> > >  planning
>> > >  for retirement in any of the following ways? Mark all that apply.">
>> > > 
>> > >  <CHOICEELEMENT CAPTION="Estate planning" VALUE="0" />
>> > >  <CHOICEELEMENT CAPTION="Drafting of a will" VALUE="1" />
>> > >  <CHOICEELEMENT CAPTION="Financial planning" VALUE="2" />
>> > >  <CHOICEELEMENT CAPTION="Investing in additional equity" VALUE="3" />
>> > >  <CHOICEELEMENT CAPTION="Researching federal or state retirement
>> > >  policy
>> > >    issues" VALUE="4" />
>> > >  <CHOICEELEMENT CAPTION="Purchasing supplemental health insurance"
>> > >  VALUE=           "5" />
>> > >  <CHOICEELEMENT CAPTION="Other" VALUE="6" />
>> > > 
>> > >  </CHOICE>
>> > > 
>> > >  Can you set ILLEGALVAL in a multi choice?
>>  Skickat av Todd Slater <[email protected]>
>>  till survey-discussion
>> 
> Skickat av Joel Palmius <[email protected]>
> till survey-discussion
>
>
mc.survey (text/plain, 1.2 KB)
<SURVEY TITLE="mc">

  <CHOICE NAME="test" MULTI="yes" CAPTION="test">
    <CHOICEELEMENT CAPTION="option 1" VALUE="1" />
    <CHOICEELEMENT CAPTION="option 2" VALUE="2" />
    <CHOICEELEMENT CAPTION="option 3" VALUE="3" />
    <CHOICEELEMENT CAPTION="option 4" VALUE="4" />
  </CHOICE>

  <SUBMIT VISIBLE="no">
    {|
      # Ugly, but at which position in the page is the multichoice?
      $multichoice_tagno = 0;

      # What value to use if empty
      $replacewith = 5;
      
      # Acquire hash with info about submitted variable (apart from
      # VALUE there is also info about things such as CAPTION, NAME
      # NUMERICAL and so on
      $valuehash = @{$self->{DATA}}[$multichoice_tagno];

      # Get submitted value
      $value = $valuehash->{VALUE};
      
      # If empty, replace value with something else
      if(!$value)
      {
        # Replace in list of submitted value (necessary if any page
        # but last)
        $session->setValue("SUBMITTED_test",$replacewith);

        # Replace in living hashed data (necessary if last page)
        $valuehash->{VALUE} = $replacewith;

        # There is no harm in doing both no matter which page. 
      }
    |}
  </SUBMIT>

</SURVEY>