Gửi một biểu mẫu với loại trường thực thể (trang, sản phẩm...)
✅ Mục đích của kịch bản:
- Lấy cấu hình biểu mẫu từ OneEntry CMS
- Người dùng chọn một trong các phần tử của thực thể
- Gửi dữ liệu đã thu thập đến API của OneEntry.
✅ Những gì bạn cần:
- Một PROJECT_URL và APP_TOKEN hợp lệ để xác thực với API của OneEntry.
- Một biểu mẫu đã được cấu hình trước trong OneEntry với một dấu hiệu (ví dụ: thực thể) và các trường bao gồm một loại "thực thể".
- Một trường biểu mẫu đã được cấu hình trước bao gồm một loại "thực thể".
📌 Quan trọng:
- Chúng tôi không xử lý lỗi trong các ví dụ này.
- Bạn có thể xử lý lỗi trong trycatch hoặc trong một cấu trúc như "await Promise.catch((error) => error)"
Kịch bản
1. Nhập oneEntry và định nghĩa url và token
Ví dụ:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Tạo một khách hàng API với hàm defineOneEntry()
Ví dụ:
const { AuthProvider, Orders, Payments, Forms } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Chúng tôi nhận dữ liệu biểu mẫu từ OneEntry CMS để tạo một biểu mẫu trên frontend với Forms.getFormByMarker()
Ví dụ:
const formData = await Forms.getFormByMarker('entity');
Kết quả:
{
"id": 2,
"attributeSetId": 1,
"type": "data",
"localizeInfos": {
"title": "Thực thể",
"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": "Danh mục",
"parentId": null,
"position": 1,
"selected": true
},
{
"id": 7,
"depth": 0,
"title": "Trang cao cấp",
"parentId": null,
"position": 2,
"selected": true
}
],
"validators": {},
"localizeInfos": {
"title": "Thực thể"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}