Home Forums Front-end Issues Math quiz anti-spam – can this be done in ACF?


Math quiz anti-spam – can this be done in ACF?

  • Hi-

    I’ve been trying to come up with a solution to this problem for a while now but it seems I’m stuck and getting more stuck the more I think about it.

    I want to add a question field to a front end form and validate the input against a predefined answer, like so: Q: “2+2″ A:”four”. However, I want the question to be randomly picked from a list of questions.

    I’ve tried a repeater, but apparently, it’s impossible to only show one subfield of a randomly selected repeater row in a form and validate the input value against another field in that row which isn’t shown in the form.

    So I had the idea to create a field-type plugin called “quiz” for which I added additional variables to the $field-object (question/answer). The question is then displayed as field “instruction”. I then created an options page for questions and answers and an options-repeater, and loaded the q/a values randomly into the additional $field variables when the form was displayed, so I could later validate against them on submit.

    The problem with this approach appears to be that acf/load_value is apparently called during the submmission/validation process as well, at which point the random row selection gets called again and potentially picks a different row from the question/answers-options-group. In which case a previously correct submitted answer will no longer be the correct answer.

    So one question would be: Is there a way in this setup to ensure that the same question and answer loaded via acf/load_value and displayed in the form prior to its submission are then used to validate the input value (without showing the q and a to bots as hidden fields in the form, which would kind of beat the purpuse)?

    Or maybe I’m going about this completely wrong? In that case my question would be: can this be done in ACF (front-end) at all?

    Thanks for any help!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.