Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Select Field with options that are titles of children pages of specific page

form

Started by Mantas 8 years ago · 0 replies · 682 views
8 years ago

In Contact Form, I need to have a Select field, with options, that are children of "Services" page.

Is it necessary to specify all option in markdown file?

I tried to overwrite user\plugins\form\templates\forms\fields\select\select.html.twig file with a loop, that would gather all pages, and write them to option tags:

TWIG
 ....
{% set service_array = [] %}
{% for item in pages.find('/services').children %}
    {% set service_array = service_array|merge( { (item.header.heading):(item.header.heading) } ) %}
{% endfor %}

{% for key, item_value in service_array %}
    <option value="{{ key}}">
        {{ item_value }}
    </option>
{% endfor %}
....

After selecting some option in contact form and pressing submit, the request file is generated in:
/user/data/home-form folder, with the option that was selected, but email is sent without this value. I think it's because i haven't specified these select options in my Markdown file

What would be the easiest way to write this Select?

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by FrViPofm, 5 days ago
5 100 4 days ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2119 7 months ago
Forms & Blueprints · by Hugo Oliveira, 8 months ago
0 604 8 months ago
Forms & Blueprints · by Flachy Joe, 9 months ago
9 694 9 months ago
Forms & Blueprints · by Augustus, 10 months ago
7 741 10 months ago