Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

teampoison's avatar

Only spinner are loading not redirect to another page but account created

i have one form in vue where i use two submit button after click on submit both are redirect to different page but they do to redirect on that page but account are created.

self.$http
        .post(self.$member_whitelist_signup, form_data)
        .then(function (response) {
          if (response.data.success == true) {
             if (this.saveClicked) {
              
              this.$router.replace({ path: '/member/member-questionnaire' });

            } else {
              // self.showModal=true
               this.$router.replace('/questionnaire');

            }
          } else {
            if (response.data.data == null) {
              self.error_msg = response.data.message;
            } else {
              let first_error_key = Object.keys(response.data.data)[0];
              self.error_msg = response.data.data[first_error_key][0];
            }
          }
0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It looks like the code is trying to redirect to different pages based on which submit button was clicked, but the redirection is not working. One possible reason for this could be that this is not referring to the Vue instance inside the then callback function. To fix this, you can store a reference to this in a variable before making the HTTP request, and then use that variable inside the callback function. Here's an example:

// store a reference to `this` in a variable
var vm = this;

self.$http
  .post(self.$member_whitelist_signup, form_data)
  .then(function (response) {
    if (response.data.success == true) {
      if (vm.saveClicked) { // use `vm` instead of `this`
        vm.$router.replace({ path: '/member/member-questionnaire' });
      } else {
        vm.$router.replace('/questionnaire');
      }
    } else {
      // handle error
    }
  });

Also, make sure that the saveClicked property is set correctly based on which submit button was clicked. You can use a v-model directive to bind the value of the submit button to a data property in Vue. Here's an example:

<template>
  <div>
    <form @submit.prevent="submitForm">
      <!-- form fields -->
      <button type="submit" v-model="saveClicked" value="true">Save and Continue</button>
      <button type="submit" v-model="saveClicked" value="false">Continue Without Saving</button>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      saveClicked: null
    };
  },
  methods: {
    submitForm() {
      // make HTTP request and handle response
    }
  }
};
</script>

Please or to participate in this conversation.