[英]Cannot submit form data to DatoCMS using Gatsby.js
I am submitting form data using this:我正在使用这个提交表单数据:
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) }
This is the error information, but I can't make heads or tails of it.这是错误信息,但我无法确定它的正面或反面。
The form's handle submit function successfully call createRecord() from the form page.表单的句柄提交 function 从表单页面成功调用 createRecord()。 So, problem would seem to be from the snippet provided.
因此,问题似乎来自提供的代码段。
I sourced said snippet from here: DatoCMS create record simple example我从这里获取了上述片段: DatoCMS 创建记录简单示例
I think you are missing the relationship between your form and the content model in DatoCMS.我认为您缺少表单与 DatoCMS 中内容 model 之间的关系。 According to the docs:
根据文档:
Suppose our project contains a "Dog" model (ID: 1234, API key: dog) with the >following fields:
假设我们的项目包含一个“Dog”model(ID:1234,API 键:dog),具有以下字段:
Field API Key 字段 API 密钥
Field Type 字段类型
name 姓名
Single-line String 单行字符串
breed 品种
Single-line String 单行字符串
description 描述
Multiple-paragraph text 多段文字
age 年龄
Integer 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();
In your case, it seems that you are not matching the itemType
, which is the model ID, as the promise output suggests in your console.log
.在您的情况下,您似乎不匹配
itemType
,即 model ID,因为 promise output 在您的console.log
中建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.