Skip to main content

Submitting a form with an entity field type (pages, products...)

✅ Purpose of the scenario:

  • Get form configuration from OneEntry CMS
  • User select one of the elements of the entity
  • Submit the collected data to an OneEntry API.

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • A pre-configured form in OneEntry with a marker (e.g., entity) and fields including one of type "entity".
  • A pre-configured form fields including one of type "entity".

📌 Important:

  • We do not handle errors in these examples.
  • You can handle errors in trycatch or in a construction like "await Promise.catch((error) => error)"

Scenario

1. Import oneEntry and define url and token

Example:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. Creating an API client with defineOneEntry() function

Example:

const { AuthProvider, Orders, Payments, Forms } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. We receive form data from OneEntry CMS to generate a form on the frontend with Forms.getFormByMarker()

Example:

const formData = await Forms.getFormByMarker('entity');
Result:
{
"id": 2,
"attributeSetId": 1,
"type": "data",
"localizeInfos": {
"title": "Entity",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 17,
"position": 1,
"identifier": "entity",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "entity",
"marker": "entity",
"isLogin": null,
"isSignUp": null,
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [
{
"id": 1,
"depth": 0,
"title": "Catalog",
"parentId": null,
"position": 1,
"selected": true
},
{
"id": 7,
"depth": 0,
"title": "Premium page",
"parentId": null,
"position": 2,
"selected": true
}
],
"validators": {},
"localizeInfos": {
"title": "Entity"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}

4. Select one of the elements of the entity type attribute and pass to value as array of ids(numbers) for pages or array of strings for products

Example:

[
{
"marker": "entity",
"type": "entity",
"value": [
1
]
}
]

5. Post forms data with FormData.postFormsData()

Example:

const response = FormData.postFormsData({
formIdentifier: 'entity',
formData: fieldsData,
});
console.log(response);
Result:
{
"formData": {
"formIdentifier": "entity",
"time": "2025-04-30T20:11:30.059Z",
"formData": [
{
"marker": "entity",
"type": "entity",
"value": [
1
]
}
],
"id": 67
},
"actionMessage": ""
}

Final example

// 1. Import oneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

// 2. Creating an API client:
const { Forms, FormData } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. We receive form data from OneEntry CMS to generate a form on the frontend
const formData = await Forms.getFormByMarker('entity');

// 4. select one of the elements of the entity type attribute
const fieldsData = [
{
marker: 'entity',
type: 'entity',
value: [
1,
],
},
];

// 5. Post forms data with FormData.postFormsData()
let response = await FormData.postFormsData({
formIdentifier: 'entity',
formData: fieldsData,
});
// console.log(response);