Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

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

form

Started by Mantas 8 years ago · 0 replies · 837 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 Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago