Returning Submit to Same Page

Aside from the obvious of using AJAX, you can achieve this by adding a query in the success URL instead of an additional segment, etc.

 
 
 




 




{% if craft.app.request.getQueryParam('success') == 1 %}
    <div class="success">Your message has been sent!</div>
{% endif %}

{% set form = craft.expressforms.form("contact") %}

{{ form.openTag({
    return: '/contact?success=1',
}) }}
    {# Form layout code goes here #}
{{ form.closeTag }}
1
2
3
4
5
6
7
8
9
10
11

Or a different option, simply redirecting to /contact?success:

 
 
 
 




 




{% set successParam = craft.app.request.getParam('success') %}
{% if successParam is not null %}
    <p>Your message has been sent!</p>
{% endif %}

{% set form = craft.expressforms.form("contact") %}

{{ form.openTag({
    return: '/contact?success',
}) }}
    {# Form layout code goes here #}
{{ form.closeTag }}
1
2
3
4
5
6
7
8
9
10
11
12

Dynamically build return URL

If you're looking for a dynamic way of setting a return URL with combining several segments:

{% set returnUrlPath = siteUrl ~ "get-quote/" ~ craft.app.request.getSegment(2) ~ "?success=1" %}
1

And for the form.openTag():


 


{{ form.openTag({
    return: returnUrlPath,
}) }}
1
2
3
Last Updated: 4/16/2019, 12:09:49 PM