Homepage

Redirecting and Displaying a Thank you Message

Last edit: Jul 24, 2024

To complete our task, we need to redirect users to a "Thank you" page (/contacts/thanks) after they successfully submit the Contact Us form.

Update the create.liquid file

Add the redirect_to logic in your create.liquid file to handle the redirection upon successful form submission.

app/views/pages/contacts/create.liquid

---
method: post
---
{% function contact = 'commands/contacts/create', object: context.params.contact %}
{% if contact.valid %}
  {% redirect_to '/contacts/thanks' %}
{% else %}
  {% render 'contacts/form', contact: contact %}
{% endif %}

This code will check if the contact creation is valid and, if so, redirect the user to the /contacts/thanks page. If the validation fails, it will re-render the form with the contact data.

Create a Thank you page

Create a simple "Thank You" page that the user will be redirected to upon successful form submission.

Create a thanks.liquid file:

app/views/pages/contacts/thanks.liquid

Add content:

app/views/pages/contacts/thanks.liquid

Thank you!

This file will display a simple "Thank you" message when the user is redirected to the /contacts/thanks URL.

app
└── views
    └── pages
        └── contacts
            ├── create.liquid
            └── thanks.liquid

Test redirection and database

Now that we have implemented the redirection and the thank you page, let's test to ensure everything works as expected.

Ensure that all modifications have been synced to your platformOS instance.

Test using invalid data

Open your Contact Us form and submit invalid data first. The form should re-render with error messages indicating the validation issues.


Displaying validation errors on the Contact Us form

Test using valid data

Now, submit the form with valid data. You should be redirected to the /contacts/thanks page, displaying the "Thank you!" message.

Verify that the data has been correctly stored in the database and confirm the new contact record.


Verifying stored data in the database post submission

Questions?

We are always happy to help with any questions you may have.

contact us