Whenever the user clicks on the "create" label, I have set up a redirection to another page. However, an issue arises when I activate the code snippet below for the redirection:
<script>
(function() {
var REDIRECT_PATH = '/pages/become-a-partner-submit';
var selector = '#create_customer, form[action$="/account"][method="post"]',
$form = document.querySelectorAll(selector)[0];
if ($form) {
$redirect = document.createElement('input');
$redirect.setAttribute('name', 'return_to');
$redirect.setAttribute('type', 'hidden');
$redirect.value = REDIRECT_PATH;
$form.appendChild($redirect);
}
})();
</script>
The form error parameters do not seem to be functioning correctly. For instance, if the password field is empty and the user clicks on the "create" button, it still redirects to the specified path. Disabling the JavaScript code resolves this issue as it prohibits users from creating an account if essential fields are left empty. How can I maintain both the form error handling and redirecting the customer after successful account creation?
Below is my complete code:
<script src="https://www.google.com/recaptcha/api.js?render=6LeJp8EgAAAAAN2IymRMhGeete2PDs2hOsRHCWvB"></script>
<div class="central py-medium" id="template">
<div id="customer">
<!-- Create Customer -->
<div id="create-customer">
<div class="template_header">
<h1 class="h2 feature-header" data-cc-animate>{{ 'customer.register.title' | t }}</h1>
</div>
...
{% comment %}
<script>
(function() {
var REDIRECT_PATH = '/pages/become-a-partner-submit';
var selector = '#create_customer, form[action$="/account"][method="post"]',
$form = document.querySelectorAll(selector)[0];
if ($form) {
$redirect = document.createElement('input');
$redirect.setAttribute('name', 'return_to');
$redirect.setAttribute('type', 'hidden');
$redirect.value = REDIRECT_PATH;
$form.appendChild($redirect);
}
})();
</script>
{% endcomment %}