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

teampoison's avatar

i have one form where user submit detail i want if user already fill then redirect to another page

For this i create this but in this question are not showing for all and if user already fill that form still its does not redirect.

else {
    self.$http
      .post(self.$get_question_answer_for_member + "?token=" + self.user_access_token, form_data)
      .then(function (response) {
        if (response.data.success == true) {
          self.questions_exist = true;
          self.questions = response.data.data;
          self.questions_length = Object.keys(self.questions).length;
          let ques_keys = Object.keys(self.questions);

          // Check if member has answered any questions
          console.log("Checking if member has answered questions. Member ID: ", form_data.get("member_id"));

          // Make a POST request to the get_member_byid API endpoint
          self.$http.post(self.$get_member_byid + self.member_profile.member_unique_id + "?token=" + self.user_access_token, form_data)
            .then(function (response) {
              // Check if preety_general_answer_giver header is equal to 1
              if (response.headers.preety_general_answer_giver === "1") {
                // Redirect to specified URL
                window.location.href = "https://example.com";
              } else {
                // Show questions
                ques_keys.forEach(key => {
                  self.questions[key].forEach(element => {
                    element["question_" + element.question_id] = "";
                    self.form["question_" + element.question_id] = "";

                    element["question_other_" + element.question_id] = "";
                    self.form["question_other_" + element.question_id] = "";
                  });
                });
                // console.warn("self.questions", self.questions);
                // console.warn("self.form", self.form);
              }
            })
            .catch(function (error) {
              console.warn(error);
            });
        } else {
                  self.questions_exist = false;
                  Vue.notify({ type: "error", title: response.data.message });
                }
              })
              .catch(function (error) {
                console.warn(error);
              });
    }
      
    },

On orignal Code question are showing

else
    {
              self.$http
              .post(self.$get_question_answer_for_member + "?token=" + self.user_access_token, form_data)
              .then(function (response) {
                if (response.data.success == true) {
                  self.questions_exist = true;
                  self.questions = response.data.data;
                  self.questions_length = Object.keys(self.questions).length;
                  let ques_keys = Object.keys(self.questions);

                  ques_keys.forEach(key => {
                    self.questions[key].forEach(element => {
                      element["question_" + element.question_id] = "";
                      self.form["question_" + element.question_id] = "";

                      element["question_other_" + element.question_id] = "";
                      self.form["question_other_" + element.question_id] = "";
                    });
                  })
                  // console.warn("self.questions", self.questions);
                  // console.warn("self.form", self.form);
                } else {
                  self.questions_exist = false;
                  Vue.notify({ type: "error", title: response.data.message });
                }
              })
              .catch(function (error) {
                console.warn(error);
              });
    }
      
    },
0 likes
1 reply
LaryAI's avatar
Level 58

To redirect the user to another page if they have already filled out the form, you can add a check before showing the questions. Here's an example:

else {
  self.$http
    .post(self.$get_question_answer_for_member + "?token=" + self.user_access_token, form_data)
    .then(function (response) {
      if (response.data.success == true) {
        self.questions_exist = true;
        self.questions = response.data.data;
        self.questions_length = Object.keys(self.questions).length;
        let ques_keys = Object.keys(self.questions);

        // Check if member has answered any questions
        console.log("Checking if member has answered questions. Member ID: ", form_data.get("member_id"));

        // Make a POST request to the get_member_byid API endpoint
        self.$http.post(self.$get_member_byid + self.member_profile.member_unique_id + "?token=" + self.user_access_token, form_data)
          .then(function (response) {
            // Check if preety_general_answer_giver header is equal to 1
            if (response.headers.preety_general_answer_giver === "1") {
              // Redirect to specified URL
              window.location.href = "https://example.com";
            } else {
              // Show questions
              ques_keys.forEach(key => {
                self.questions[key].forEach(element => {
                  element["question_" + element.question_id] = "";
                  self.form["question_" + element.question_id] = "";

                  element["question_other_" + element.question_id] = "";
                  self.form["question_other_" + element.question_id] = "";
                });
              });
              // console.warn("self.questions", self.questions);
              // console.warn("self.form", self.form);
            }
          })
          .catch(function (error) {
            console.warn(error);
          });
      } else {
        self.questions_exist = false;
        Vue.notify({ type: "error", title: response.data.message });
      }
    })
    .catch(function (error) {
      console.warn(error);
    });
}

In this example, we're checking if the user has already answered the questions by making a POST request to the get_member_byid API endpoint. If the preety_general_answer_giver header is equal to 1, we redirect the user to https://example.com. Otherwise, we show the questions as usual.

Note that you'll need to replace https://example.com with the URL you want to redirect the user to.

Please or to participate in this conversation.