Craft docs的Entry Form示例不起作用

问题描述

我对Craft很陌生,来自ExpressionEngine世界。我正在学习如何创建前端输入表单。我已经设置了一个部分,创建了一些字段,并为表单创建了模板以进行输入。

{% macro errorList(errors) %}
  {% if errors %}
    <ul class="errors">
      {% for error in errors %}
        <li>{{ error }}</li>
      {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

{# If there were any validation errors,an `entry` variable will be passed to the
   template,which contains the posted values and validation errors. If that’s not
   set,we’ll default to a new entry. #}
{% set entry = entry ?? create('craft\\elements\\Entry') %}

<form method="post" accept-charset="UTF-8">
    
  {{ csrfinput() }}
  {{ actionInput('entries/save-entry') }}
  {{ redirectInput('missed-connections/{slug}') }}
  {{ hiddenInput('sectionId','1') }}
  {{ hiddenInput('enabled','1') }}
  
    <label for="title">Title</label>
    {{ input('text','title',entry.title,{
    id: 'title',class: entry.hasErrors('title') ? 'error',}) }}
    {{ _self.errorList(entry.getErrors('title')) }}
    
    <label for="body">Body</label>
    {{ tag('textarea',entry.body,{
    id: 'body',name: 'body',class: entry.hasErrors('body') ? 'error',}) }}
    {{ _self.errorList(entry.getErrors('body')) }}  

  <input type="submit" value="Publish">
</form> 

以上代码直接从工艺文档中复制并针对Section等进行了调整。渲染页面失败,并出现两个错误

public function tagFunction(string $type,array $attributes = []): string

class: entry.hasErrors('body') ? 'error',

创建的字段名称为“ body”,sectionID正确。

当我用以下代码替换“正文”字段的代码(这个想法在本网站的其他地方找到)时,页面将起作用,并且我可以提交条目:

  <label for="body">Body</label>
  <textarea id="body" name="fields[body]" rows="20"></textarea>

我的问题是,当静态HTML字段(上面)起作用时,为什么文档中的示例代码不起作用?

如果要使用静态HTML字段,那么如何使错误报告起作用,此外,对于更高级的字段(例如文件上载和标签),我如何加载适当的CSS /脚本以进行渲染并具有它们可以像手工艺品后端那样发挥作用?

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)