You will need to use JavaScript, either AJAX calling to a template that re-runs a new Twig for
loop and returns the results in HTML, or a framework like Vue or React in conjunction with P&T's Element API that will create an endpoint of your section's entries in JSON format.
If you don't mind a page refresh, you can filter your entries dynamically using craft.request
to grab pretty much whatever you want: a segment from the URL, query string, post data, etc. So basically, when the form submits, your redirect url should go to that page and either you add submitted data to the url via get
or grab the data via post
.
Also, fyi, you have some fundamentala syntax errorserror in theyour code you posted: no =
sign when setting a variable, missing a %)
inat the end of your else.relatedTo
tag, missing double curly braces for printing a variable, etc.;)