View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
06482Bug reportsSurvey takingpublic2012-09-20 14:12
Reporterlolo Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.00RC8 
Fixed in Version2.00+ 
Summary06482: Default values of hidden fields are not saved when taking survey
Description

When defining a hidden field with a default value, the field value is not saved when the survey is taken / submitted.

The survey answers table contains a column for the hidden field, but it is always set to NULL.

Tested with RC8.

Steps To Reproduce

1) create survey

2) add question group

3) add question #1 (visible):

  • Code: MOOD
  • Question: Mood?
  • <save>

3) add question #2 (hidden):

  • Code: RATING
  • Question Type: List (radio)
  • Mandatory: Yes
  • Advanced settings:
    Always hide this question: Yes
  • <save question>

4) edit answer options for question #2:

  • click "Edit answer options for this question"
  • click <Quick Add…>
    Enter: Good, average, bad (one per line)
  • click <Replace>
  • click <Save changes>

5) edit default answers for question #2:

  • click "Edit default answers for this question"
  • select "Good"
  • click <Save>

6) activate survey

7) take survey

  • enter anything for question #1, then submit

8) browse survey answers
-> hidden field is not shown

9) inspect survey answers table
-> column exists for hidden field, but value is always NULL

Additional Information

Sample survey joined in attachment.

TagsNo tags attached.
Attached Files
Bug heat6
Complete LimeSurvey version number (& build)120803
I will donate to the project if issue is resolvedNo
BrowserSafari 5.1.7 (Mac)
Database type & versionMysql 5.5.24
Server OS (if known)Linux 2.6.27.52
Webserver software & version (if known)Apache 2
PHP Version5.3.14

Users monitoring this issue

There are no users monitoring this issue.

Activities

lolo

lolo

2012-08-14 23:49

reporter   ~20427

Update: Just re-read my synopsis and description:
By "hidden fields" I am actually meaning "hidden questions", sorry for using the wrong term.

c_schmitz

c_schmitz

2012-08-19 00:32

administrator   ~20514

Thomas, is that supposed to work?

TMSWhite

TMSWhite

2012-08-19 07:08

reporter   ~20519

This works properly in 1.92+. Default values for hidden variables are saved.

c_schmitz

c_schmitz

2012-08-19 18:44

administrator   ~20531

In browser responses the hidden field is shown - it's hard to see because that question has no question text. (and so that particular row no header).

TMSWhite: Where in EM is the logic to save the default value for a hidden question? Because I can't find it...

TMSWhite

TMSWhite

2012-08-20 16:04

reporter   ~20552

Carsten-

This code in em_manager_helper.php::_ValidateQuestion() sets the default values:

// Regardless of whether relevant or hidden, if there is a default value and $_SESSION[$LEM->sessid][$sgqa] is NULL, then use the default value in $_SESSION, but don't write to database
// Also, set this AFTER testing relevance
$sgqas = explode('|',$LEM->qid2code[$qid]);
foreach ($sgqas as $sgqa)
{
    if (!is_null($LEM->knownVars[$sgqa]['default']) && !isset($_SESSION[$LEM->sessid][$sgqa])) {
        // add support for replacements
        $defaultVal = $LEM->ProcessString($LEM->knownVars[$sgqa]['default'], NULL, NULL, false, 1, 1, false, false, true);
        $_SESSION[$LEM->sessid][$sgqa] = $defaultVal;
    }
}

And this code, in ProcessCurrentResponses() saves the hidden default values to the database:

if ($qinfo['info']['hidden'] && !isset($_POST[$sq]))
{
    $value = (isset($_SESSION['survey_'.$LEM->sessid][$sq]) ? $_SESSION['survey_'.$LEM->sessid][$sq] : '');    // if always hidden, use the default value, if any
}
else
{
    $value = (isset($_POST[$sq]) ? $_POST[$sq] : '');
}

However, there is a bug in that code - it should be $_SESSION[$LEM->sessid], not $SESSION['survey'.$LEM->sessid], which is probably the source of the error.

c_schmitz

c_schmitz

2012-08-22 23:49

administrator   ~20571

Fix committed to Yii branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=9417

c_schmitz

c_schmitz

2012-08-22 23:49

administrator   ~20572

Thank you very much for the hint!

Related Changesets

LimeSurvey: Yii 5b83d048

2012-08-22 14:49:37

c_schmitz

Details Diff
Fixed issue 06482: Default values of hidden fields are not saved when taking survey
Dev Thank you, Thomas!
Affected Issues
06482
mod - application/helpers/expressions/em_manager_helper.php Diff File

Issue History

Date Modified Username Field Change
2012-08-14 23:42 lolo New Issue
2012-08-14 23:42 lolo File Added: survey_archive_957581.zip
2012-08-14 23:49 lolo Note Added: 20427
2012-08-15 00:13 c_schmitz Assigned To => c_schmitz
2012-08-15 00:13 c_schmitz Status new => assigned
2012-08-19 00:32 c_schmitz Note Added: 20514
2012-08-19 00:32 c_schmitz Assigned To c_schmitz => TMSWhite
2012-08-19 00:32 c_schmitz Status assigned => feedback
2012-08-19 07:08 TMSWhite Note Added: 20519
2012-08-19 07:08 TMSWhite Assigned To TMSWhite =>
2012-08-19 08:43 c_schmitz Assigned To => c_schmitz
2012-08-19 08:43 c_schmitz Status feedback => assigned
2012-08-19 18:44 c_schmitz Note Added: 20531
2012-08-20 12:50 c_schmitz Assigned To c_schmitz => TMSWhite
2012-08-20 12:50 c_schmitz Status assigned => feedback
2012-08-20 16:04 TMSWhite Note Added: 20552
2012-08-20 16:04 TMSWhite Assigned To TMSWhite => c_schmitz
2012-08-20 16:04 TMSWhite Status feedback => assigned
2012-08-22 23:49 c_schmitz Changeset attached => LimeSurvey Yii 5b83d048
2012-08-22 23:49 c_schmitz Note Added: 20571
2012-08-22 23:49 c_schmitz Resolution open => fixed
2012-08-22 23:49 c_schmitz Note Added: 20572
2012-08-22 23:49 c_schmitz Status assigned => resolved
2012-08-22 23:49 c_schmitz Fixed in Version => 2.00+
2012-09-20 14:12 c_schmitz Status resolved => closed