我是Grav CMS的新手。我在一个模块化页面中创建2个表单(联系表单和应用程序/注册表单)时遇到问题。有可能吗?
答案 0 :(得分:3)
您现在可以使用Form 2.0插件执行此操作!
这很简单,如果您的模块化页面上有两个模块,在您的情况下,联系表单和注册表单。
这意味着您有两个这样的MarkDown文件:
contact_form.md:
---
title: contact_form_modular
forms:
contact_form:
name: contact
action: /home
fields:
-
name: email
label: Email
validate:
required: true
buttons:
-
type: submit
value: Submit
process:
-
save:
fileprefix: register-
dateformat: Ymd-His-u
extension: txt
body: "{% include 'forms/data.txt.twig' %}"
operation: add
-
message: 'Thank for contacting us !'
---
## Modular title
Here a form to contact me
register_form.md:
---
title: register_form_modular
forms:
register_form:
name: register
action: /home
fields:
-
name: email
label: Email
validate:
required: true
-
name: password
label: Password
validate:
required: true
buttons:
-
type: submit
value: Submit
process:
-
email:
from: "{{ config.plugins.email.from }}"
to: "{{ config.plugins.email.to }}"
subject: "Contact by {{ form.value.name|e }}"
body: "{% include 'forms/data.html.twig' %}"
-
save:
fileprefix: register-
dateformat: Ymd-His-u
extension: txt
body: "{% include 'forms/data.txt.twig' %}"
operation: add
-
message: 'Thank for registering'
---
## Modular title
Here is a form to register to my app !
然后在主题的模板文件夹中的 contact_form.html.twig 文件中,添加以下行以呈现表单:
{% include "forms/form.html.twig" with {form: forms('contact_form')} %}
register_form.html.twig :
也是如此{% include "forms/form.html.twig" with {form: forms('register_form')} %}
当然,如果您愿意,您可以制作自己的form.html.twig,以便能够自定义表单的外观,将新文件放在主题模板文件夹中的表单文件夹中。
例如: template / forms / register_form_template.html.twig
在您的 register_form.html.twig 中,您更改为:
{% include "forms/register_form_template.html.twig" with {form: forms('register_form')} %}
我希望我已经清楚了,但在这里是文档的链接: