# 会員登録後に会員登録完了ページに遷移させたい(ただし、エラーがある場合は会員登録ページに戻したい)

**URL:** <https://community.shopify.com/t/topic/24258>\
**Category:** 技術的なQ＆A\
**Created:** [November 4, 2020, 5:25am UTC](https://community.shopify.com/t/topic/24258 "2020-11-04T05:25:36Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![toi4](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/toi4/32/122174_2.png) [@toi4](https://community.shopify.com/u/toi4)\
**Post date:** [November 4, 2020, 5:25am UTC](https://community.shopify.com/t/topic/24258/1 "2020-11-04T05:25:36Z")

</div>

Debutテーマを利用して、現在会員登録ページを作成しています。

Debutでは会員登録した後デフォルトだとトップページに飛ばされますが(カートに商品がある場合はチェックアウトに飛ぶ)、そうではなくページ機能で作成した会員登録完了ページ(/pages/register\_completed)にとばしたいと考えております。

そこで色々調べたところ、下のようなコードをtheme.liquidのタグの上に置いたら良いとか、

[https://community.shopify.com/c/Shopify-Design/Redirect-after-customer-registration/td-p/293044/page/3](https://community.shopify.com/c/Shopify-Design/Redirect-after-customer-registration/td-p/293044/page/3)

```auto
<!-- Handle registration redirect -->
<script>
  $(document).ready(function(){
    var $returnTo = $('<input type="hidden" name="return_to" value="/pages/register_completed" />');

    if ($('#create_customer').length > 0){ //if registration form
      $returnTo.insertBefore($('#create_customer input[type="submit"]')); // add return_to input
    } else if ($('#g-recaptcha').length){ //if captcha form
       $returnTo.insertBefore($('.shopify-challenge__container input[type="submit"]'));
    }
  });
</script> 

```

[https://heliumdev.com/blog/shopify-redirect-after-registration/](https://heliumdev.com/blog/shopify-redirect-after-registration/)

```auto
<script>
  (function() {
    var REDIRECT_PATH = '/pages/register_completed';

    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>

```

の方法が見つかりましたが、これらの方法では、確かに会員登録完了ページにリダイレクトしてくれますが、エラーがある時(項目を未入力、一度会員登録したことあるメアドで登録)であっても会員登録完了ページに遷移してしまいます。

エラーがある時は、会員登録ページに戻され、会員登録が成功したときだけ会員登録完了ページに飛ばす良い方法はないでしょうか？

---

_[View the full topic](https://community.shopify.com/t/topic/24258)._
