Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

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

form

Started by Mantas 8 years ago · 0 replies · 527 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 Ton Haarmans, 5 years ago
13 1144 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago