Forms: Can redirect be dynamic depending on user's selection in form?


Depending on visitor’s choice in a select list in a form, I would like to redirect to the page defined in the select list.

Can we do it at the process step or should I do it more informdata.html.twig or with my own form processor ?

What I would like to have (in the idea)

    action: /home
    name: newsletter-list
            name: newsletter_list
            type: select
            default: info
                info: 'Infos'
                animation: Animation 
                animation-laser: 'Animation Laser'
                animation-miniji: 'Animation Miniji'
                animation-420: 'Animation 420/470'
                animation-opti: 'Animation Optimist'
                animation-pav: 'Animation Planche à voile'
                animation-habitable: 'Animation Habitable'
                animation-ecole-de-voile: 'Animation Ecole de Voile'
                animation-competition: 'Animation Compétition'
            type: submit
            value: Submit
            message: 'Thank you for your feedback!'
            redirect: '/newsletter/{{ newsletter_list }}

I’m in a modular page also for the context.

So far, seems content for redirect is never intrepreted in any ways :-/


No, Twig is not processed currently in the redirect destination. Maybe the easy way to do this is to add a redirect in the display page with {{ redirect_me() }} but it’s only available in the current 1.1.9 RC, not in the stable version.


I ended so far with an ugly head override and injection of some javascript in the display page to do the redirection. It works but I’m not really proud of this :wink:

{% block head %}
{{ parent() }}
{% if == "newsletter-list" %}
{% for index, field in form.fields %}
    {% set input = attribute(field, "input@") %}
    {% if input is null or input == true %}
        {% if == 'newsletter_list' %}
        <script type="text/javascript">window.location.replace("{{ "/newsletter/" ~ string(form.value( }}")</script>
        {% endif %}
    {% endif %}
{% endfor %}
{% endif %}
{% endblock %}

Will wait for 1.9 to be stable to improve this ; thanks !