2016-08-18 23 views

回答

2

您現在可以使用Form 2.0插件來做到這一點!

而且它是非常簡單的,如果你有例如兩個模塊的模塊化頁面上,你的情況,接觸形式登記表

意味着你有兩個降價的文件是這樣的:

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文件在templ中您的主題吃的文件夾,你把下面一行來渲染形式:

{% 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能夠自定義表單的外觀,將新文件放置在主題的模板文件夾中的表單文件夾中。

例如:模板/表格/ register_form_template.html.twig

而在你register_form.html.twig你改變這樣的:

{% include "forms/register_form_template.html.twig" with {form: forms('register_form')} %} 

我希望我已經明確但在此處鏈接到文檔:

https://learn.getgrav.org/forms/forms#multiple-forms

+1

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分,並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Nuageux

+1

在這裏你更好的答案! – mhlsf

相關問題