Question T4116
Visible to All Users

Backend libraries for working with forms and form data

created 5 years ago (modified 5 years ago)

I skimmed through your GitHub repositories, but wasn't able to find this, so consider this a feature suggestion.

I think it would make a great addition to your ecosystem if you provided backend libraries to work with SurveyJS forms and submitted data. I'm talking about about the following components at the very least:

  1. a parser to convert form definition JSON into semantic objects that can be worked with
  2. a parser to convert submitted form data into semantic objects that can be worked with
  3. a validato to check whether submitted form data is valid (satisfies all constraints) or not

I suppose this is probably possible if one uses JavaScript in the backend, but it seems there are no such libraries for other programming languages (such as PHP in my case). And I think this is really important, because without such libraries, both form definitions and form data are just bare JSON strings, with no clear structure or meaning. Without a way to parse them into meaningful objects, there's no way to process that data on the server side.

Just to be clear, I'm not talking about simple json_decode here. While this function will convert JSON into objects and/or arrays, these objects and arrays will have no semantics (such as information about the field type) attached to them.

Answers approved by surveyjs Support

created 5 years ago

Hello Rimas,
Do you mean remove all values that are incorrect: remove values for non existing questions or non-existing choices?
We have this kind of method: survey.clearIncorrectValues();
If you have a survey model (load the json into survey) and have the previous created data, then the code will be the following:

JavaScript
survey.data = yourData; survey.clearIncorrectValues(); let correctData = survey.data;

Thank you,
Andrew
SurveyJS Team

    Comments (2)

      Yes, that's what I meant, but I meant data validation in the backend during form submission, which, I would typically prefer to do in PHP.

      Also, let's say I wanted to implement data export or even data processing in the backend. To do that reliably, I would need to know what type of data each field holds, so that I can process it accordingly (e.g. output a file URL for attachment fields, or flatten/rearrange matrix output for matrix fields). Right now, it seems this can only be done in JS, but not in other languages (unless of course I want to reverse engineer and specify the JSON the formats, and then write a library to work with these formats myself).

        Hello Rimas,
        You can do the validation on server using NodeJS. We have the ability to build a survey without a rendering part.
        Regarding other languages, there are many different platforms and server languages. You need php, some people ask about similar functionality on C# and so on. Unfortunately, it would require to repeat a good part of our SurveyJS on different languages to support this functionality.

        Thank you,
        Andrew
        SurveyJS Team

        Other Answers

        created 5 years ago

        Just for the reference, it seems a PHP library similar to what I was talking about is being developed in this repository. I haven't investigated it too much, and it only supports a few question types so far, but it appears promising.

          Comments (1)

            Thank you, we will take a look.

            Andrew
            SurveyJS Team