Adding a cancellation survey
Create a new contact form with an email and a message field. Name the custom form url
cancel
:
Name Message field Reason for cancellation
.
In form rules → custom code add this code:
<!-- handle subscription cancellation form -->
<script>
var orderId = new URL(window.location).searchParams.get('order');
sessionStorage.setItem('cancelOrder', orderId);
// hide email field which is required in contact forms
$('#email').parents('.form-group').hide();
</script>
Update the cancellation link to point to this form:
In clients/subscription.twig
replace
<a
href="/portal/subscriptions/{{ subscription.order.number }}/cancel"
data-toggle="modal"
data-target="#spp-modal"
class="dropdown-item {{ subscription.status ? '' : 'disabled' }}">
{{ lang('subscriptions.cancel') }}
</a>
with
<a
href="/contact/cancel?order={{ subscription.order.number }}"
class="dropdown-item {{ subscription.status ? '' : 'disabled' }}"
data-pjax>
{{ lang('subscriptions.cancel') }}
</a>
In
clients/ticket.twig
add this code right after{% block content %}
<!-- handle subscription cancellation form -->
<script>
let urlParams = (new URLSearchParams(window.location.search));
if (urlParams.has('_reload') && sessionStorage.getItem('cancelOrder')) {
window.location.replace('/portal/subscriptions/' + sessionStorage.getItem('cancelOrder') + '/cancel');
}
</script>
How this works
Cancellation link points to a contact form with the order ID in the url. that order ID is saved in session.
After the form is filled out it creates a ticket.
In that ticket we’ve added a code that redirects the user to the actual cancellation page.