You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

提交Craft CMS前端条目表单时遇'Request missing required body param'错误

解决Craft CMS前端条目表单的「Request missing required body param」错误

核心问题与修复步骤

1. 缺少必填的栏目(Section)参数

保存新条目时,Craft必须明确知道要将条目存入哪个栏目,你的表单未传递该参数,这是报错的直接原因。添加以下隐藏字段(二选一即可):

{{ hiddenInput('sectionHandle', 'dogs') }} {# 替换成你实际的栏目句柄 #}

或用栏目ID:

{{ hiddenInput('sectionId', 1) }} {# 替换成你实际的栏目ID #}

2. 自定义字段命名错误

featureImage属于自定义字段,表单中需以fields[字段句柄]作为name属性,而非直接用字段名。修改后的代码:

{{ input('file', 'fields[featureImage]', entry.featureImage|default(''), {
  id: 'featureImage',
}) }}

3. 分类字段的正确配置

你的分类选择框存在两处错误:

  • name属性:若允许多选分类,需改为fields[postCategories][];单选则用fields[postCategories]
  • option值:必须使用分类ID而非标题,否则无法正确关联分类

修改后的分类选择代码:

<select name="fields[postCategories]" id="postCategories"> {# 多选则改为fields[postCategories][] #}
  {% set myCategoryQuery = craft.categories().group('blog') %}
  {% set categories = myCategoryQuery.all() %}
  {% for category in categories %}
    <option value="{{ category.id }}" {% if entry.postCategories is not empty and entry.postCategories.id == category.id %}selected{% endif %}>
      {{ category.title }}
    </option>
  {% endfor %}
</select>

注:原代码中{% nav %}标签生成的<li>放在<select>内无效,需改用普通循环。

4. 移除无用的entryId字段

创建新条目时无需entryId参数,直接删除<input type="hidden" name="entryId" value="">即可,该参数仅在编辑现有条目时需要。


内容的提问来源于stack exchange,提问作者George Bleasdale

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 12:20:35