I am looking to redirect customers to a specific page after they create an account on the store. Here's the code from customers/register.liquid :
<div id="customer">
<!-- Create Customer -->
<div id="create-customer">
{% form 'create_customer' %}
{{ form.errors | default_errors }}
<div id="first_name" class="clearfix large_form">
<label for="first_name" class="login">{{ 'customer.register.first_name' | t }}</label>
<input type="text" value="" name="customer[first_name]" id="first_name" class="large" size="30" />
</div>
<div id="last_name" class="clearfix large_form">
<label for="last_name" class="login">{{ 'customer.register.last_name' | t }}</label>
<input type="text" value="" name="customer[last_name]" id="last_name" class="large" size="30" />
</div>
<div id="email" class="clearfix large_form">
<label for="email" class="login">{{ 'customer.register.email' | t }}</label>
<input type="email" value="" name="customer[email]" id="email" class="large" size="30" />
</div>
<div id="password" class="clearfix large_form">
<label for="password" class="login">{{ 'customer.register.password' | t }}</label>
<input type="password" value="" name="customer[password]" id="password" class="large password" size="30" />
</div>
<p class="action_bottom">
<input class="btn action_button" type="submit" value="{{ 'customer.register.sign_up' | t }}" />
<span class="note">{{ 'customer.register.or' | t }} <a href="{{ shop.url }}">{{ 'customer.register.cancel' | t }}</a></span>
</p>
{% endform %}
</div><!-- /#create-customer -->
</div>
I looked at this doc, but it didn't work...
Any suggestions?
Place this in script tags at the bottom of your registration form liquid page
It's the only way that shopify allows it.
jQuery(function() {
jQuery('#create_customer').submit(function(event) {
event.preventDefault();
var data = jQuery(this).serialize();
//create new account
jQuery.post('/account', data)
.done(function(data){
var logErrors = jQuery(data).find('.errors').text();
//if there are errors show them in the html form
if (logErrors != "" && logErrors != 'undefined'){
jQuery('#create_customer .errors').html(logErrors);
jQuery('#create_customer .errors').show();
//if account creation is successful show checkout page
}else{
console.log('success');
document.location.href = '/checkout';
}
}).fail(function(){console.log('error');});
return false;
});
});
For sure - that will work on the login page, but will fail on the registration template - not sure about a page that has both forms on it. The code I posted will work as a workaround for the same function on a REGISTRATION form.
Update on this. When using this script, I noticed that due to Shopify enforcing the recapta page after more than 1 login attempt from the same IP address, this causes the form to go nowhere. Not good for testing. When you do create an account for the first time, this script works! Does anyone have any ideas on how to update the script to avoid nothing happening if they have attempted to create an account more than once from the same IP address? I doubt this will happen a lot but would create a bad user experience.
You can either change the error script in the code so that it displays a message telling them to wait a few days or you can contact shopify support and have them turn off the spam filter. They don’t recommend it but I did it for testing.
User | Count |
---|---|
458 | |
189 | |
139 | |
61 | |
42 |