Registration Using Ajax

We've added the ability to register using ajax so that the registration form can be hosted on squarespace

The code for the button above which you will need to add as a code block looks like this:

<script>
$(function() {
    var form = $('#xly-registration-form');
    form.submit(function(event) {
        event.preventDefault();
        var submitButton = form.find('#xly-register');
        submitButton.val('Registering...');
        $.ajaxSetup({
            xhrFields: {
                withCredentials: true
            }});
        $.post( "https://portal.buyexpressly.com/sign-up/register.ajax", form.serialize())
            .done(function(data) {
                form.find('.form-item').removeClass('error');
                form.find('.xly-error').removeClass('field-error');
                form.find('.xly-error').hide();
                                
                if (!data.success) {
                    $.each( data.errors.fieldErrors, function( key, value ) {
                        var fieldDiv = form.find('#xly-' + key);
                        var fieldError = fieldDiv.find('.xly-error');
                        fieldDiv.addClass('error');
                        fieldError.text(value);
                        fieldError.show();
                        fieldError.addClass('field-error');
                    });

                    if (data.errors.globalError) {
                        var globalError = form.find('#xly-globalError');
                        globalError.text(data.errors.globalError);
                        if (data.errors.globalErrorHelp) {
                            globalError.text(globalError.text() + '. ' + data.errors.globalErrorHelp);
                        }
                        globalError.show();
                        globalError.addClass('field-error');
                        submitButton.val('Register!');
                    }
                } else {
                    window.location.replace(data.redirect);
                }
            });
    });
});
</script>

<div class="form-wrapper" > 
  <div class="form-inner-wrapper">
    <form autocomplete="on" id="xly-registration-form">
                <div class="xly-error" id="xly-globalError" style="display:hidden"></div>
        <div class="field-list clear">
            <div class="form-item field text required" id="xly-fullName">
                <div class="xly-error" style="display:hidden"></div>
                <label class="title">Full Name</label>
            <input type="text" class="field-element text" name="fullName">
          </div>
            <div class="form-item field text required" id="xly-phone">
                <div class="xly-error" style="display:hidden"></div>
                <label class="title">Phone Number</label>
              <input type="text" class="field-element text" name="phone">
            </div>
            <div class="form-item field email required" id="xly-email">
                <div class="xly-error" style="display:hidden"></div>
                <label class="title">Email Address</label>
            <input type="text" x-autocomplete="email" spellcheck="false" class="field-element" name="email">
            </div>
            <div class="form-item field text required" id="xly-password">
                <div class="xly-error" style="display:hidden"></div>
                <label class="title">Password</label>
              <input type="password" class="field-element text" name="password">
            </div>
            <div class="form-item field select required">
                    <label class="title">Who are you?</label>
                <select name="preferencePartnerType" id="preferencePartnerType">
                    <option value="TAKER">A Brand</option>
                    <option value="GIVER">A Publisher</option>
                    <option value="BOTH">Both</option>
                </select>
            </div>
        </div>
        <div class="form-button-wrapper form-button-wrapper--align-center">
            <input class="button sqs-system-button sqs-editable-button" id="xly-register" type="submit" value="Register"/>
        </div>
    </form>
  </div>
</div>