0

I have a webform that we have people fill out two times - for a pre-test and a post-test and I am looking for a way to determine if a pre-test has been taken an if so, set a specific value on form element.

Currently we have people manually select whether they are taking the pre-test or post-test in a webform element, but they are not doing so very accurately. Given we have the data to know that, I am hoping to be able to determine that automatically in a webform field.

Here are some more details:

  • We gather a unique participant id (c_ID)
  • Based on that participant ID I am hoping to validate if a previous webform submission with that participant ID exists.
    • If not: Provide a value of "pre-test"
    • If so: Provide a value of "post-test"

Does anyone have any recommendations on how something like this could be done?

2
  • Are the pre- and post-test submissions the same submission? Or are they separate submissions? Do both submissions have the same fields? And where does participant ID come from?
    – Joseph
    May 3, 2022 at 19:00
  • Thanks @Joseph - pre and post-test both use the exact same webform with the same fields, but are completed at different times, usually days or weeks apart. Currently whether it is a pre- or post-test is a select box in the same field. The participant ID is entered manually by the person filling out the form. May 3, 2022 at 19:51

1 Answer 1

1

Configure the select element containing "pre-test" and "post-test" options to have "Prepopulate" checked. Remember the machine name of the element, that will be the query parameter for the succeeding steps (e.g. submission_type)

Then create a block with a textfield asking for a participant ID. On submit, it would look for a webform submission already containing the ID. Then one of two things can happen:

  • If a submission doesn't exist yet, redirect the user to the webform with the "pre-test" pre-selected (e.g. ?submission_type=pre-test)
  • If a submission already exists, redirect the user to a webform with "post-test" pre-selected. (e.g. ?submission_type=post-test)

Then pop this block wherever you want to start this workflow, like on some page. As an added bonus, you could make the block ask for the query parameter name used in the redirect during its configuration. That way, you can match the webform element name without having to dive into code later should you rename it.

I also recommend putting a warning saying the field was pre-filled based on participant ID's existence. Prefills are easy to overlook.


Alternatively, just provide two links to the webform, one with ?submission_type=pre-test bolted onto its url and the other with ?submission_type=post-test. Same effect minus the participant ID checking and custom block (assuming the user chooses the right link).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.