Best Practices for Retrieving a Form Schema

2025/02/05 7:27 AM

I am creating a controller for a custom API endpoint. On a GET request, it returns a form schema (defined in the Forms application) so an external app can render the form dynamically. On a POST request, it validates and stores the submitted data in the XbyK database.

I have outlined the solution but am unsure of the best way to obtain the form schema. The most reasonable source seems to be the CMS_Class table, specifically the ClassFormDefinition field, which stores the schema as an XML document. While I can retrieve and parse this field via the XbyK API, it feels cumbersome, and I assume there’s a more efficient approach.

I’d appreciate guidance on the best way to retrieve the full form schema, including the submit button, so I can properly render fields with the right attributes and validate values on submission in an external app by consuming the custom API endpoint.


Environment

  • Xperience by Kentico version: [30.1.0]
  • .NET version: [8|9]

Answers

2025/02/06 3:35 AM
Answer

The APIs used to render or process form submissions in Xperience are all abstract, generic, and often know nothing about the context they are used in.

They reflect on the form class and form XML definition, do validation with instantiated form components, render, etc...

So I think our code is probably similar to what you are doing. I'm guessing if we do have higher level APIs than what you are doing they are internal.

Form Builder forms just aren't designed for headless rendering today, even though some partners take that approach.

If you'd like to see better headless rendering support let us know via the roadmap - we have discussed it internally but haven't prioritized it yet.

I'd be interested to see examples of headless form rendering from anyone who has tried it.

2025/02/12 11:32 AM

Okay, so the short answer seems to be that there’s currently no API that provides the form schema in a reasonable way. No problem—I just wanted to confirm that since I couldn’t find any guidance online or by digging into the API.

That said, I managed to create a proof of concept using the XML schema and got it working. Around the same time, I also participated in a UX research research, where it looks like Kentico is considering adding Headless Forms to the product in the future. Since this is more of a discovery project, I’m willing to wait for built-in support.

In any case, I’d appreciate any updates if you decide to add it to the roadmap.

2025/02/12 4:08 PM

One additional note - you can generate C# code files for Forms defined in your project.

While it's not the form "schema", it is the form data structure. This could give you a strongly typed API for form retrieval or persistence.

There's an example in the Kentico Community Portal.

Maybe you can combine this with the Form data management APIs to get what you want. However, any custom validation or Form Component behavior (business rules baked into the Form itself) will not apply here.

To answer this question, you have to login first.