Question T3740
Visible to All Users

Any suggestions on how to implement server-side validation of the posted survey?

created 5 years ago

As no data received from the client should be trusted, I want to validate that the posted result.data conforms to the questionnaire.

A straight-forward way would be to use json schema for that, although it is still a draft.

However, it wouldn't be capable of validating all of my constraints: questions that are only conditionally required (by use of VisibleIf), or use custom validation, like

JavaScript
{panel.DateStart} <= {panel.DateEnd}

Also, it would require to keep a json schema up to date with the questionnaire.

So, I was considering to use a server-side javascript engine to load and run SurveyJS and just validate the result on the server. The result of a failed validation might be to direct the submitted result to a separate list, for further investigation.

Does that sound like a good idea, or are there serious pitfalls? Or, is there a better solution for this that I just missed?

Answers approved by surveyjs Support

created 5 years ago

Hello,
Unless you are using NodeJS on your server, it would be really hard and would require to recreate Survey Model code on server side, using a language of your server platform. Months and months of works.
Everything is easy with NodeJS, you can just run our survey model (without rendering) and write several lines of code on JavaScript, as you do for browser.
You can make a specific checks on server, but really it doesn't related to SurveyJS. It is about data in JSON format and your rules. I am afraid we can't suggest something specific here. We are just a client JavaScript Library.

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 5 years ago

    I understand that it would require a javascript engine to make it feasible and NodeJS is the most promising option.

    I also understand that this is not for SurveyJS to solve. That's why I made the question public.

    Anyway, thanks for your swift reply. I have enough information to go with.

      Comments (1)

        You are very welcome!

        Andrew
        SurveyJS Team