Integrating a survey tool in your web application
Facing the question how to implement a basic survey functionality within a web application, I had several options:
- Implementing a new system from scratch
- Linking to an external hosted system
- Integrating an existing 3rd party survey tool into the web application
The survey features were important, but would not justify a big amount of workload, so implementing a new system from scratch (that would give enough flexibilty to support different types of question types and complex ways of analyzing results) was out of the question.
The downside of this decision was that the survey administration will not be integrated into the rest of the administration interface, but we could live with that.
Linking to an external hosted system (like SurveyMonkey or SurveyGizmo) sounded nice, but I needed to be able to control access to the survey via tokens – so that a single user could answer a certain survey only once by using a token issued to him by me.
Most of the external hosted survey tools have no problem using tokens, but I needed to dynamically generate this token within my web application right before I send the user the invitation to answer the survey, so I needed to be able to insert new tokens at runtime from my application – and could not figure out how to do that using a hosted system.
By integrating an existing solution, I would be able to have direct access to the (local) database, inserting tokens on the fly.
What I ended up doing was using the open source LimeSurvey. It’s a standard PHP/mySQL application, and seems like the defacto standard solution for surveys on the web.
LimeSurvey can serve all sorts of question types, and – most importantly – use tokens to control access to restricted, non-anonymous surveys.
These tokens are stored in DB tables named tokens_<SURVEYID> whereas <SURVEYID> is (you guessed it) the numerical ID of the survey.
Now, if you construct the SQL update statement manually, it’s pretty easy to concat the survey ID into the statement string, but since I was already using Hibernate, I wanted to refrain from hardcoding SQL in my application.
After some research, I implemented a custom Hibernate Interceptor, which allowed me to insert the surveyID into the SQL-string on the fly without any other hassle.
I will write more about how we use and trigger the survey invitations in a later post.
Interesting! Do tell us more.