Submitting a form with a file attachment
✅ Purpose of the scenario:
- Retrieve form configuration from OneEntry CMS
- The user completes a form (e.g., response, feedback).
- Attaches a file (image, resume, document).
- The data and file are stored together in FormData
- Submit the collected data to the OneEntry API.
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- A form in OneEntry with a field of type "File" (type file)
- Form marker (e.g., resume_form)
📌 Important:
- We do not handle errors in these examples.
- You can handle errors using try-catch or in a structure 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 { Forms, FormData } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
Example:
const fileForm = await Forms.getFormByMarker('file');
Result:
{
"id": 8,
"attributeSetId": 11,
"type": "data",
"localizeInfos": {
"title": "File",
"titleForSite": "",
"successMessage": "Successful data processing",
"unsuccessMessage": "Unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 1,
"identifier": "file",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "file",
"marker": "file",
"isLogin": null,
"isSignUp": null,
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "File"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "image",
"marker": "image",
"isLogin": null,
"isSignUp": null,
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Image"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "groupOfImages",
"marker": "images_group",
"isLogin": null,
"isSignUp": null,
"position": 3,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Images group"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}
3. Uploading a file with form input=file
Send
Data:
// JS
let selectedFiles = null;
// handleFileChange
const handleFileChange = (e: any) => {
selectedFiles = e.target.files;
};
// handleSubmit
const handleSubmit = async (e, file) => {
e.preventDefault();
// 4. Preparing form data
const body = {
formIdentifier: 'file',
formData: [
{
marker: 'file',
type: 'file',
value: file,
fileQuery: {
type: 'page',
entity: 'editor',
id: 4965,
},
},
],
};
// 5. Submitting a form with FormData.postFormsData()
const postFormResp = await FormData.postFormsData(body);
};
Example:
// HTML
<form
onSubmit={(e) => handleSubmit(e, selectedFiles)}
className="flex flex-col gap-3 p-10 border rounded-3xl"
>
<input
type="file"
onChange={handleFileChange}
className="bg-white text-slate-800 p-3 rounded-2xl"
/>
<button
type="submit"
className="bg-white text-slate-800 p-3 rounded-2xl"
>
Send
</button>
</form>
Result:
{
"formData": {
"formIdentifier": "file",
"time": "2025-05-12T22:28:57.531Z",
"formData": [
{
"marker": "file",
"type": "file",
"value": [
{
"filename": "files/project/page/4965/editor/process-svgrepo-com-1747088937134.svg",
"downloadLink": "https://test-data.oneentry.cloud/cloud-static/files/project/page/4965/editor/process-svgrepo-com-1747088937134.svg",
"size": 67066
}
]
}
],
"id": 76
},
"actionMessage": "Successful data processing"
}
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,
});
const fileForm = await Forms.getFormByMarker('file');
// 3. Uploading a file with form input=file
// JS
const selectedFiles = [];
const handleFileChange = (e) => {
selectedFiles = e.target.files;
};
// handleSubmit
const handleSubmit = async (e, file) => {
e.preventDefault();
// 4. Preparing form data
const body = {
formIdentifier: 'file',
formData: [
{
marker: 'file',
type: 'file',
value: file,
fileQuery: {
type: 'page',
entity: 'editor',
id: 4965,
},
},
],
};
// 5. Submitting a form with FormData.postFormsData()
const postFormResp = await FormData.postFormsData(body);
};
// HTML
<form
onSubmit={(e) => handleSubmit(e, selectedFiles)}
className="flex flex-col gap-3 p-10 border rounded-3xl"
>
<input
type="file"
onChange={handleFileChange}
className="bg-white text-slate-800 p-3 rounded-2xl"
/>
<button
type="submit"
className="bg-white text-slate-800 p-3 rounded-2xl"
>
Send
</button>
</form>