Forum

Thread tagged as: Question, Forms

Populate dynamically a select form field

I am currently implementing a method to filter results on pages, and I am looking at this example from the docs https://solutions.grabaperch.com/architecture/user-filtered-lists.

It works nicely, but I am trying to pass a string to the "options" of the html "select" element in order to handle it dynamically, like so

PerchSystem::set_var('materials_list', $materials_list); // creating the string in php
<perch:input id="material" type="select" options=" <perch:content id="materials_list" />  " /> // inside the form template

I find that passing variables in the <perch:form> does not work as it does in regular <perch:content> templates.

I don't know why this is so and I am wondering if there is a solution to be able to populate the field options dynamically.

Spyros Perris

Spyros Perris 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which page function are you using to display the form?

I am using perch_form()

Drew McLellan

Drew McLellan 2638 points
Perch Support

Then a <perch:content /> tag won't be parsed.

Try <perch:forms /> instead.

Sweet! Thank you