Hi.
I am having a problem creating 2 forms (contact form and application/register form) in one modular page. Is it possible?
Hi.
I am having a problem creating 2 forms (contact form and application/register form) in one modular page. Is it possible?
It will be very possible, even without modular pages very shortly. If you are feeling adventurous you can test this out in the mutliple-form branch: https://github.com/getgrav/grav-plugin-form/tree/feature/multiple_form_handling
With this you will be able to define multiple forms in a page called `/form’:
forms:
form-a:
fields:
...
buttons:
...
process:
...
form-b:
fields:
...
buttons:
...
process:
...
Then to output a form you would simply do this in your Twig:
{% include "forms/form.html.twig" with {form: forms('/form', 'form-a')} %}
{% include "forms/form.html.twig" with {form: forms('/form', 'form-b')} %}
---
I initialized my form in modular.md page
forms:
form-a:
action: /your-modular-page
name: application_form
fields:
-
name: name
label: name
placeholder: 'Full name’
type: text
validate:
required: true
-
name: email
label: email
placeholder: 'Your email’
type: email
validate:
required: true
-
name: company_name
label: company_name
placeholder: 'Company Name’
type: text
validate:
required: true
buttons:
-
type: submit
value: Submit
body: “{% include ‘forms/data.txt.twig’ %}”
process:
- email:
from: "{{ config.plugins.email.from }}"
to: "{{ form.value.email }}"
subject: "Contact by {{ form.value.name|e }}"
body: "{% include 'forms/data.html.twig' %}"
-
message: 'Thank you for your feedback!'
form-b:
action: /your-modular-page
name: contact_form
fields:
-
name: name
label: name
placeholder: 'Full name'
type: text
validate:
required: true
-
name: email
label: email
placeholder: 'Your email'
type: email
validate:
required: true
and include my file
{% include “forms/applicationform.html.twig” with {form: forms(’/form’, ‘form-a’)} %}
but it’s not working. It returns a blank page. Do have any idea? Maybe I miss something.
I downloaded the multiple_form_handling on the link you sent me and now I got this error
here is my modular.html.twig content
— html
{% extends ‘partials/base.html.twig’ %}
{% block content %}
{{ page.content }}
{% for module in page.collection() %}
{{ module.content }}
{% endfor %}
{% endblock %}
That field is included with the form plugin, are you sure you installed it correctly?
It doesn’t have error now but the 2 forms is not working. Is it okay to put the form in modular.md, under the modular pages? Form-a is working/displaying but form-b doesn’t.
I tested with modular pages and it worked fine for me. Make sure you clear the cache between each change because Twig caching for modular pages is very aggressive.