• Resolved sksidhuk

    (@sksidhuk)


    I have a quiz form created with Forminator. It has 15 questions with 3 options with radio field. Radio option has values 1, 2, and 3 for all questions. At the end I need to calculate which options the user selected most and based on that show the answers. 
    For example: if the user selected most 1s then answer will be "Kapha", for 2 most selected it will be "Pitta" and for 3s it will be "Vatta"
    I have created three hidden fields to store 1s, 2s, and 3s answers count. And hidden-4 will store the result. And this hidden-4 will be shown as a result to the user and also need to this in email.

    This is the JS I am using in my footer.php before </body> tag. This JS working fine in console.log displaying the results. but no answer is storing and sending to emails.


    <script>

    function initializeDoshaScript() {

    const form = document.querySelector('form.forminator-custom-form');

    if (!form) {

    console.log("❌ Form not found yet. Retrying...");

    setTimeout(initializeDoshaScript, 300);

    return;

    }

    console.log("✅ Form found. Attaching submit handler.");

    form.onsubmit = function () {

    console.log("🟢 Form is about to submit...");

    let countOne = 0;

    let countTwo = 0;

    let countThree = 0;

    const selectedRadios = form.querySelectorAll('input[type="radio"]:checked');

    console.log("📌 Selected radios:", selectedRadios);

    selectedRadios.forEach(function (radio) {

    const val = radio.value.trim().toLowerCase();

    console.log('Value in each: ',val);

    if (val == 1) countOne++;

    else if (val == 2) countTwo++;

    else if (val == 3) countThree++;

    });

    const oneField = form.querySelector('input[name="hidden-1"]');

    const twoField = form.querySelector('input[name="hidden-2"]');

    const threeField = form.querySelector('input[name="hidden-3"]');

    const resultField = form.querySelector('input[name="hidden-4"]');

    console.log('resultField: ', resultField);

    if (oneField && twoField && threeField ) {

    oneField.value = countOne;

    twoField.value = countTwo;

    threeField.value = countThree;

    let result = '';

    if (countOne > countTwo && countOne > countThree && resultField) {

    result = 'Vata';

    } else if (countTwo > countOne && countTwo > countThree) {

    result = 'Pitta';

    } else if (countThree > countOne && countThree > countTwo) {

    result = 'Kapha';

    } else {

    result = 'Mixed Body Type';

    }

    resultField.value = result;

    console.log('resultField: ', resultField.value);

    console.log("🔢 one:", countOne, "two:", countTwo, "three:", countThree);

    console.log("🧘 Dosha result:", result);

    } else {

    console.log("⚠️ Hidden fields not found!");

    }

    // Let the form submit as usual

    return true;

    };

    }

    document.addEventListener('DOMContentLoaded', initializeDoshaScript);

    </script>

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @sksidhuk ,

    I hope you’re doing well.

    The Quiz should actually show a result based on what is checked on your questions, you can assign a “personality”, for example, to each reply and show it at the end if one of these personalities were shown more than other – https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#personalities-personality-quizzes-only

    Could you please confirm if this is what you need to achieve or something else?

    In case it’s not what you want to achieve, could you confirm what you need to do with the custom code?

    I hope to hear back from you soon.
    Best Regards,
    Williams Valerio

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sksidhuk,

    We have not received any response from you for some time, so we will proceed to mark this thread as resolved. If you need more assistance in the future, please feel free to reach out, and we will be glad to continue helping you.

    Best Regards,
    Nebu John

    Thread Starter sksidhuk

    (@sksidhuk)

    Sorry for the late response. I tried the “personality” and it worked. That what i wanted to achieve. Great pluign!

    Thanks for your support!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Quiz calculation not working’ is closed to new replies.