Welcome, Guest
Username: Password: Remember me

TOPIC: Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table

Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table 1 year 2 months ago #100009

  • utsi
  • utsi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: -2
Suppose I have a survey with id '123'.

Someone comes across a multiple choice question and selects 2 out of the 5 options. Now I would like to store '1' in the database for checked options and '0' for the other 3 options (instead of blank) in the lime_survey_123 table.

I'm finding it difficult to locate the file which handles the live survey post data. I can figure out where to change the values if I know which file is responsible for inserting data into the survey respondant table.

Any ideas on where I should look for that file?

Thanks.
Last Edit: 1 year 2 months ago by utsi.
The administrator has disabled public write access.

Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table 1 year 2 months ago #100010

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2962
  • Thank you received: 381
  • Karma: 124
I don't where to change this either, but just want to point you to something: if you change that, many other things (reporting, etc.) of limesurvey might brake.

Why do you need to change this on creation? Because if it is for external analysis, you can change that during the download process.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table 1 year 2 months ago #100012

  • utsi
  • utsi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: -2
I'm aware that some things might get affected if I do that. But I'm willing to take the risk. I'll test locally first and see what the consequences would be and if whether it is worth the risk or not.

Coming back to this weird requirement, to put it in simple terms the main aim is to differentiate between questions which have been shown to respondents and which didn't.

For example:
If a multi question is displayed, the answers that are checked should be stored as 1 in database and unchecked answer options as 0.

And if a multi question is not shown, then the present system of nothing being stored database should kick in.

My requirement is pretty similar to the one mentioned here limesurvey.org/en/forum/future-features/...tion-not-shown#99752
The administrator has disabled public write access.

Change value of Checkbox from 'Y' to '1' Before Inserting into Respondent Table 1 year 2 months ago #100026

  • utsi
  • utsi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: -2
I finally managed to track down the page which deals with insertion to the database. I modified the original code from
if (is_null($val))
{
	$setter[] = dbQuoteID($key) . "=NULL";
}
else
{						
	$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);
}

to
if (is_null($val))
{
	$setter[] = dbQuoteID($key) . "=NULL";
}
else
{
	if($type == 'M')
	{	
		if($val == '' || empty($val))
		{
			$val = '0';
		}
		$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);
	}
	else
	{							
		$setter[] = dbQuoteID($key) . "=" . dbQuoteAll($val);	
	}						                        
}

This is working as expected i.e. if the question of type "M" is shown to the respondent and he checks 2 out of the 5 checkboxes, the checked checked values are stored as "Y" while the rest unchecked values are stored as 0 AND if the question of type "M" is skipped due to masking, nothing gets stored in the database.

The only thing I need to verify now is that this doesn't mess up the values of other questions of the survey.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.210 seconds
Donation Image