无法使用 Gatsby.js 将表单数据提交到 DatoCMS
Cannot submit form data to DatoCMS using Gatsby.js
我正在使用此提交表单数据:
const { SiteClient } = require("datocms-client")
const client = new SiteClient("APIKEYREMOVED")
export default async function createRecord(fields) {
console.log('@submit function ',fields)
const record = await client.items.create(fields)
console.log(record)
}
这是错误信息,但我看不懂。
表单的句柄提交函数成功地从表单页面调用了createRecord()。因此,问题似乎来自提供的代码段。
我从这里获取了上述片段:DatoCMS create record simple example
我认为您忽略了 DatoCMS 中表单和内容模型之间的关系。根据文档:
Suppose our project contains a "Dog" model (ID: 1234, API key: dog) with the >following fields:
Field API Key
Field Type
name
Single-line String
breed
Single-line String
description
Multiple-paragraph text
age
Integer
const { SiteClient } = require("datocms-client");
const client = new SiteClient("YOUR-API-TOKEN");
async function createRecord() {
const record = await client.items.create({
itemType: "1234", // model ID
name: "Gigio",
breed: "Labrador",
description: "Very friendly and calm.\nI love it.",
age: 4,
});
console.log(record);
}
createRecord();
在您的情况下,您似乎没有匹配模型 ID itemType
,正如您的 console.log
.
中的承诺输出所暗示的那样
我正在使用此提交表单数据:
const { SiteClient } = require("datocms-client")
const client = new SiteClient("APIKEYREMOVED")
export default async function createRecord(fields) {
console.log('@submit function ',fields)
const record = await client.items.create(fields)
console.log(record)
}
这是错误信息,但我看不懂。
表单的句柄提交函数成功地从表单页面调用了createRecord()。因此,问题似乎来自提供的代码段。
我从这里获取了上述片段:DatoCMS create record simple example
我认为您忽略了 DatoCMS 中表单和内容模型之间的关系。根据文档:
Suppose our project contains a "Dog" model (ID: 1234, API key: dog) with the >following fields:
Field API Key Field Type name Single-line String breed Single-line String description Multiple-paragraph text age Integer const { SiteClient } = require("datocms-client"); const client = new SiteClient("YOUR-API-TOKEN"); async function createRecord() { const record = await client.items.create({ itemType: "1234", // model ID name: "Gigio", breed: "Labrador", description: "Very friendly and calm.\nI love it.", age: 4, }); console.log(record); } createRecord();
在您的情况下,您似乎没有匹配模型 ID itemType
,正如您的 console.log
.