Workarounds: Further solutions provided by LimeSurvey users

Here you can find workarounds/solutions provided by LimeSurvey users which do not deal with these workaround sections:
 * Workarounds: Question design, layout and templating
 * Manipulating a survey at runtime using Javascript
 * Survey behaviour.

If you are looking for general troubleshooting please check our General FAQ and Installation FAQ. If you can't find a solution for your problem please open a new thread at our forum or ask at our live chat.

'''Please keep in mind that the workarounds published here are no official LimeSurvey extensions but solutions that other users created for themselves. Therefore we can't give support for any solution on this page. Please contact the users that, thankfully, shared their solutions with the community if you have any questions.'''

=How to import survey responses from v1.00 into v1.5x (and later)=

Tested with: LS >= 1.50

In LimeSurvey v1.50 it´s possible to import a survey, which is generated (and exported) with v1.00 into v1.5x. The Problem is, on that way only the survey structure gets imported, but no respones to that survey.

If you also need to import the responses, follow the next steps:
 * 1) Export your survey in v1.00
 * 2) Do a VV-Export in v1.00 (to save your responses)
 * 3) Import your survey from v1.00 into v1.5x via "Create or Import a New Survey" in the main Admin Panel
 * 4) Activate your imported survey
 * 5) Fill out your survey once, so that at least one response is in your database.
 * 6) Do a VV-Export in v1.5x
 * 7) Open both VV-Exports (v1.5x and v1.00); if you use Microsoft Excel do it via "Open New File" and "Import from Text-File" or "Import from external source - textfile" and choose "seperated" and "Unicode (UTF-8)"; choose
 * 8) Compare the file structure and you´ll see that there are two columns added (submitdate and startlanguage) and that all question codes changed.
 * 9) Copy all rows (except row 1 and 2, that means you start with the third row) from your VV-Export  v1.00 into your VV-Export v1.5x (also put it at the third row)
 * 10) Add the columns "submitdate" and "startlanguage" in your VV-Export v1.5x-File, right between "id" and "token"
 * 11) Save your file (in Microsoft Excel use Textfile - Tabstopp seperated). It´s necessary that your file after saving has the same format as before - Notice: it´s not a normal .csv-File.
 * 12) Import your file via VV-Import

=Translate surveys without admin access=

Tested with: 

User "CasN" has written a nice extension that allows you to translate surveys without having access to the admin panel. He has added his files in the bug and feature tracker (01735: Remote translating feature) where you can download them. You'll also find a short How-To there.

This is how it works:

Copy the scripts in the root of your survey directory and call starttrans.php like this starttrans.php?survey=12345

It will check the languages connected to the survey and also verify the labelsets used.

You will then get a screen with for each language the required links for translating, aswell for the labels as the survey itself. From the survey, the question and tip fields are presented for translation.

Thanks CasN for sharing your solution with the community!

=Create Question Pools=

Tested with: 

This is a simple solution to create question pools for LimeSurvey. It will require access to the backend database. I'm not going to explain how to do this, as if you don't understand it, then you shouldn't really do it.

Basically 3 tables exist that we care about:
 * lime_surveys - id field = sid
 * lime_groups - id field = gid
 * lime_questions id field = qid

In order to show the questions correctly the id field from the lime_groups table exists in the lime_questions table. This then is used to create the parent/child relationship.

However, if you want to create a pool of questions all you need to do is to amend the gid field in the lime_questions table to a value that doesn't exist in the lime_groups table. I would use 0 or a something silly like 10000. Try this with one question and you will notice it doesnt appear in the question list.

It's a crude workaround, but allows you to create as many questions as you want, without having them visible.

This could also be applied for groups as well just by using the sid field in the lime_groups table.

=Re-open a submitted answer=

Tested with: 1.71+

As an administrator you can re-open a submitted answer.
 * 1) Reset tokens invitation to not sent
 * 2) Reset answers to not completed
 * 3) release <= 1.72: In LS <= 1.72 you don't have the option to "Reset answers to not completed" that version 1.8 offers, so this would require the following workaround:
 * 4) export of tokens
 * 5) vvexport of answers
 * 6) deactivate/activate survey in order to erase answers
 * 7) import answers from VVimport but Add the 'import as not finalized answers' option
 * 8) import tokens
 * 9) release >= 1.8:
 * 10) from the answer summary page, a new option can be used to reset all answers to a not submitted state
 * 11) from the tokens summary page, you can reset all tokens to 'not sent' state

Note that this will work only on non anonymous surveys with "Allow Persistence" option set.

=Bypassing email check at registration=

When you allow public registration to your survey LimeSurvey developers have opted to put in place a certain level of protection from bots and spammers by placing a captcha and by forcing the users to go and check their emails to find the link associated with their tokens.

Sometimes, however, this is a nuisance that actually force people to wait for the email when they would rather just take the survey and get on with things. Ideally it would be great if a token-based survey present the participant a short-text box (like a security question) asking at random one of the field in the registration form when the token is passed via URL (i will put this as feature request for the next edition!).

In the meantime, there is a very easy workaround. The solution is to edit the register.php and add the following code around line 156 (where the code is rewriting the page with the message that the email has been sent):

Whatever you want to say

I placed right on line 156 between the two line breaks. The code is simply creating a link to the survey embedding the token in the URL.

NOTE that this is literally bypassing the safety currently in place, but the advantage is streamlining the steps for taking the survey with registration.

=Alternate Bypassing Email Check at Registration=

For version 1.87, please add the following code on line 180 above the //PRINT COMPLETED PAGE in register.php. This will take the user directly to the welcome page without any pauses in between and bypasses the user having to go to the email validation to start the survey.

header("Location: $publicurl/index.php?sid=$surveyid&token;=$newtoken");

- Zad Imam 04/20/2010

=Used email and public registration=

Tested with v1.8

When you have a closed survey with public registration, currently LimeSurvey is not allowing a user to re-use the same email. This is a problem if the user has deleted the registration email without taking the survey. In the above workaround a user was allowed to take a survey by presenting a link straight after the registration; ideally they should be prompted with an additional security question and/or captcha (see bugtracker). In the meantime, this owrkaround allows you to from a link from the corresponding email and present it to the user.

Make sure you back up your register.php first!

Here the querystring has been modified to pull out the token as well as the email address and the error message has been changed to display the link to the survey for the existing token. Please also note that this forced change will not be reflected in the different languages!

Around line 75 find the corresponding code:

=HTTP-Refferer is not shown after a Redirect=

There are different ways to redirect a page, just as HTTP-Redirect 301, meta http-equiv="Refresh", meta http-equiv="Referrer", link rel="canonical" or JavaScript window.location. But all of them don't work correct in all Browsers when it comes up to the HTTP-Referer. The only working solution I found is with a bit strange JavaScript. You see the solution at

=Provide a preview-all-questions page for any survey=

Sometimes people would like to be able to preview all questions in a survey before actually taking the survey - it gives them a chance to prepare their information in advance. While the LimeSurvey admin tool lets you create a printable version of a survey, this is not really appropriate for end users, as it contains placeholders for token values, etc. So, for our installation I created a separate PHP script, which you can install on your server and provide for users. Further notes are in the body of the script:

";

break;

case 'Z';    // Flexible drop-down/radio-button - user selections come from lime_labels; here, show all possible options

$output .= '';    // Begin tag for bulleted list of options

$qLabels = mysql_query("SELECT title FROM lime_labels WHERE lid={$row['lid']}");

while ($rowOpts = mysql_fetch_assoc($qLabels)) {

$output .= ''. $rowOpts['title']. '';

}

$output .= '';

break;

default:    // For any type not specified above, no further output after displaying the question text

break;

}    // END: switch ($row['type'])

}    // End main loop thru survey questions (while ($row....)

return ($output);

}

/******

stripFinalBrk: Test if string ends with a tag, and if so remove it; returns modified string.

function stripFinalBrk($myString) {

$yerString = strrev($myString);    // Reverse input string for testing

// Check if *reversed* string begins with a tag (backwards) - if so, strip out starting characters and return the rest

if (substr($yerString,0,6) == '>/ rb<')

$yerString = substr($yerString,6);

return(strrev($yerString));    // Reverse back for result

}

?>

LimeSurvey Preview Page

body {

font-family: Helvetica, Verdana, sans-serif;

padding:1em 0 2em 1em;

font-size:0.9em;

}

td, th {

font-size:0.8em;

}

li {

font-size:0.9em;

}

h2 {

color:#00A;

}

div.qText {

margin:1em 0 0.5em 0;

padding:0.5em 0 0.2em 0;

border-top: solid 1px #00a;

/* border-bottom: solid 1px #00a; */

}





=How to export a clean up-to-date .doc questionnaire directly from LimeSurvey=

Once we have programmed a questionnaire we sometimes need to export it back. For example, we have made some changes directly in the interface, and would like to save them in a human-readable way for reference. Or, maybe our client needs to make some changes in the plain old .doc format.

While LS lacks such a function it is still possible to do this with free software and a little effort.

Step 1: go to the printable version of your questionnaire

http://img401.imageshack.us/img401/1535/e7e788d275844deeb207679.png

Step 2: using your browser save the html file of the questionnaire locally.

Step 3: open the file using Libre Office.

Step 4: save/export the document as .doc.

Step 5: beautify the result. In your word processor of choice you may want to align all text to the left and use some automated way to put a border on your tables (use this http://www.thedoctools.com/index.php?show=mt_tableborder if you have MsWord)

That's it. Now you have a file that can be sent to your clients or edited.

Notes

For step 2, you may actually want to consider exporting to PDF by using a PDF printer as Bullzip PDF or CutePDF. Your partners may use one of the many PDF annotation tools to comment. On the plus side, it will look a bit better, keeping checkboxes and stuff.

However, not all people are comfortable using this. Even more importantly, I have found that when it exports questionnaire logic in human-readable form the text becomes hard to follow or even stops making sense.

For step 3 you can, theoretically, use other tools like Word or OpenOffice. However the matrix-intensive survey I used for testing crashed all software except LO. Depending on the questionnaire you may need to take other decisions.

=Notepad++ macro to replace. with;=

If you try to paste a list like this

1. option1

2. option2

... into the quick add box in LimeSurvey it will likely not wok out nicely because it will keep the numbering in the label of the option. However if you change it to ...

1; option1

2; option2

... it will work just fine, creating both codes and labels. I have created a Notepad++ macro that replaces the. following numbers up to 30 with ;, provided that all numbers are at the beginning of the line.

To install it you must

1. Close Notepad++ and keep it closed (otherwise it will override your work)

2. Search for shortcuts.xml in the program folder

3. Open it with another text editor

4. In the macro section paste the code below.

Note that N++ does not have something like an "echo off" command, so you will get lots of feedback from the program while the macro runs. However, I have created several smaller macros so that you may want to choose based on how wide your numbers range. (It will all come clear once you actually run the macro)

Now the code:

=Procedure to translate all surveys in the desired language quick and easy=

Step 1: Setup LimeSurvey


 * 1) 	Install all new fonts in the Computer/ Server
 * 2) 	Add language folders in ~\htdocs\locale
 * 3) 	Go to ~\htdocs\application\helpers and insert commands for the desired languages in SurveyRuntimeHelper.php
 * 4) 	Go to ~\ htdocs\third_party\ckeditor\_source\plugins\font and edit Plugin.js file using notepad++. Press ctrl+f and                                       search for ‘verdana’. Add all the fonts that you have installed in step A.
 * 5) 	Go to ~\htdocs\third_party\ckeditor and edit ckeditor.js file using notepad++. Press ctrl+f and search for ‘verdana’. Add all the fonts that you have installed in step A.

Note: Step 1 is to be performed only once. You can skip this step for all subsequent projects.

Step 2: Export Survey


 * 1) 	Export your Survey in .txt (UTF-8 format).
 * 2) 	Open the .txt file in excel.

Step 3: Import Translations


 * 1) 	Look for the language code in the .txt file. Copy all ‘en’ entries of the questions (with their respective answer options) on a new excel sheet.
 * 2) 	Now open the translated excel sheet shared by the client and perform vlookup. Check for errors and incomplete translations.
 * 3) 	Once all translations are done, copy the translated entries and paste them in automated translations.xlsx sheet.
 * 4) 	Final step. Now, copy the output generated from the automated translations.xlsx sheet and paste it in the .txt file.

Step 4: Save and Upload


 * 1) 	Save the .txt file in the same format i.e. Tab Delimited.
 * 2) 	Now open LimeSurvey and Import the survey.

=Provide a basic statistic without the need of an user account (for example to provide a stat for your client)=

This PHP script shows the number of the participants of surveys and the development of the participations presented with a Google Line Chart. There are three key-features: 1. The necessary survey ID's and the title of the project are provide with GET variables so anyone can set up the statistic without the need to adapt the source code 2. The client can see the development with the help of Google Charts 3. Real time count of the overall number of participants

Further the script can handle also surveys where the dates weren't logged and the surveys can also be mixed.

All you need is to provide a URL following this pattern http://yourdomain/survey_stat.php?survey=1010101,2020202,3030303&title=Client%20Name

survey= Here you provide the survey ID's from one or different surveys (when the client runs more than one survey or you want to compare different surveys) title = Here you provide the title

That's it. It is pretty easy and can be set up from anyone.

Here is the full script ready to go with google JS and HTML code:

=Import & show data into a Google Drive Spreadsheet=

Tested with: LS >= 2.05

You can import any data (e.g. list of surveys or users, selected answers) stored in your limesurvey database using the "IMPORTXML" function.
 * 1) Create a XML file to structure and print needed data (you should access it at http://mysite.com/myxml.php )
 * 2) In your spreadsheet use the following format (pasting in a cell):

To protect your XML file(s) from direct access you can put them in a dedicated folder and use a .htacess file to limit the access exclusively to Google Apps web crawlers filtered by ip ranges

PHP (XML output) file sample.

The following php file will generate an XML view printing ID, STARTDATE and STARTLANGUAGE values of a survey.

=Force HTTPS only for admins (not survey takers) with .htaccess= Add this to your .htaccess in the Limesurvey installation folder. And replace the myLimeFolder and domain name to whatever you have repecively.

=Pre-filling a lot of answers in a survey= There are three things necessary to pre-fill questions easily in LimeSurvey: Let's assume you have a survey completed except for not having set up prefilling of questions. Note that, if all your questions are of a simple type (no array type or multiple choice questions), you don’t need the third step, and you can simply use the "Edit default answers" button to assign the values. The place to start is adding a bunch of attributes to the regular token table. At some point, according to the documentation, it was possible to specify how long each of the additional attributes should be. In my current version (2.50+) this is no longer a part of the token management screen, and all the tokens created have length 255. This means that you rapidly run out of space in the tokens table (at about 85 columns in utf8 character set). Limesurvey is perfectly happy if you downsize the columns, which you can do by running an "alter table modify …" on columns of the lime_tokens_ table. MySQL does not allow the SQL variant dealing with more than one row at a time, so most efficient is to write a script to create the one-column-at-a-time statements, e.g.: Once you have added the raw columns (which will be called attribute_1 to attribute_n) you can give them more meaningful names. This is of limited practical value (see below), but should help keep you organized. The values that you import into the token table presumably come from a database somewhere. Whatever method works best to create a CSV file with the attribute data in it is good. The csv should have: Alternatively, when you export the token table, the column headers will look like "attribute_8" which you could transpose in Excel to use as the list. In my case I created a table in the database with meaningful column names, and then had to write a query to turn then back into columns named attribute_1 through attribute_n, like: d. You import the csv data into limesurvey using the "Create tokens" button and the "Import tokens from CSV file" option. The third part of the process is to write the code to copy the values from the token table to the survey variable for which they are required. The place to put this code is in the Question box of an question that is of type "Equation", and which has an advanced setting of "Always hide this question" = "Yes". The ExpressionScript (introduced about version 1.96) makes assigning the values from the TOKEN to the survey field quite easy. Each assignment should look something like: If you look in the forums you will see answers circa 2011 where it was necessary to write little javascript functions to prefill the values. This is no longer necessary. Note that:
 * 1) A token table that will store the prefill values loaded from the csv file
 * 2) A table (a .csv file works well), with the prefill values
 * 3) Code to copy the prefill values where they need to go
 * 1) At least three of the regular token table columns: firstname, lastname, email, but it can have any of the other standard columns you need (obviously with prefills you will not be doing anonymous surveying), as well as the attribute columns you use for prefilling.
 * 2) Columns called attribute_1 through attribute_n. The columns cannot be called by the alias names that you might have given them in the first step. Clearly this means that you (as the programmer in the database from which the information is being brought), need to have some sort of concordance list  that tells you that "attribute_23" is the data of birth of the 3rd child (or whatever). In limesurvey the concordance  is stored in JSON in the attributedescriptions column of the appropriate row in the lime_surveys table. You can extract it in MySQL using "select attributedescriptions from lime_surveys where sid = ", and you should then be able to format it with one row per line and use that to guide writing the .csv file.
 * 1) The values that you put in the .csv file will be most useful to you if they correspond to the Code of your possible responses. If, for example, your answer options screen gives a code = A1, answer option = "Yes", then "A1" is what you want in your data. If you don’t do this you will need to do something like the method mentioned in the last bullet below.
 * 1) The whole expression is enclosed in curly braces
 * 2) Case is important (for the survey column names and the token attribute)
 * 3) The "if(is_empty(..)" part of the expression prevents you overwriting values that the person filling in the survey has already manually changed.
 * 4) In the above example, II2 is the question code, and the _1 denotes the first element of the array. More strictly the "1" is the code of the array element. If the code was SQ1 then you would use _SQ1, and so on.
 * 5) Above I stated that there was little practical value in naming the attribute columns. If you click on the lime in curly braces icon at the top of the question box (second icon), you will get a list of the attributes in the token file with their meaningful names. This is nice, but when you select a particular token, the TOKEN:ATTRIBUTE_x gets added to your box surrounded by curly braces. That would be fine if you were trying to customize text in the box, but it's not good within our assignment statement: it's a syntax error. You then have to go to the Source screen to remove the braces, so it is probably just as quick to type TOKEN:ATTRIBUTE_x, assuming you have your list handy.
 * 6) You can add multiple EM assignment statements in a single question.
 * 7) If your token attribute is not actually what you need to put into the survey variable, then you can use an "if" function to transform it, e.g. your imported data has 'Yes' and you need to set the variable to A1, otherwise A2 use:

=Insert a JavaScript file into a custom admin theme (LimeSurvey 2.06)=


 * Create your own admin template - see Custom Admin Themes
 * Add a custom JavaScript file to your new template directory
 * Extract the attached [[Media:InsertAdminJS.zip|insertAdminJS plugin folder]] in your /plugins directory
 * In Plugin manager, activate the "Insert Custom Admin JS File" plugin
 * If you have named your custom JS file something other than "custom.js", go to the plugin settings and enter the filename

You will then see the custom JavaScript file inserted into all admin pages: