Trigger quiz passed
Hi Beniamino,
I really can’t provide any direction without more information. Are you doing this client side or server side? What does “not working anymore” mean?
HD Quiz 2.0 uses the same on_submit action, so there are no issues with compatibility there. The only advice I can give is to debug your code. Check what data you are collecting and sending to the server.
Hi,
thanks for your reply. Here’s a detailed explanation of my issue.
I’m using a server-side snippet that was working correctly with HD Quiz v1.8, but after updating to v2.0, it stopped working. Specifically, the function hdq_a_light_submit_action is no longer triggered after quiz submission.
The code hooks into the hdq_submit action and appends my custom function “hdq_a_light_submit_action” to $quizOptions->hdq_submit, like this:
php
Copia
Modifica
function hdq_a_light_submit($quizOptions) {
array_push($quizOptions->hdq_submit, “hdq_a_light_submit_action”);
return $quizOptions;
}
add_action(‘hdq_submit’, ‘hdq_a_light_submit’);
Then I define the function hdq_a_light_submit_action($data) to process the quiz results (reading data from $_POST[‘data’]) and update custom user fields using ACF.
Finally, the function is registered via:
php
Copia
Modifica
add_action(‘wp_ajax_hdq_a_light_submit_action’, ‘hdq_a_light_submit_action’);
add_action(‘wp_ajax_nopriv_hdq_a_light_submit_action’, ‘hdq_a_light_submit_action’);
Since the update to HD Quiz 2.0, this flow is no longer working — my function is not being called, and I don’t see any AJAX request for my custom action being sent to admin-ajax.php.
Can you please confirm:
Is hdq_submit still the right hook to add custom submit actions?
Is $quizOptions->hdq_submit still supported and used by the frontend?
Has the quiz submission mechanism changed in v2.0? If so, what’s the new way to run server-side custom logic after submission?
Thanks a lot!
Beniamino
As I previously said:
> HD Quiz 2.0 uses the same on_submit action, so there are no issues with compatibility there.
It looks like you modified the Save Results Light addon, so I recommend downloading the latest version of that so that you can see how it all works and is connected.
If you go to a page with a quiz on it, and open up your browser console, entering HDQ.VARS.hdq_submit will print out the array that contains the name of all functions to run once the quiz completes.
If you see your action listed there, then you know that the action was correctly registered, and that HD Quiz is calling it. If this is the case, then are you sure that the ajax call isn’t happening? Did you do something that could have affected this, like some security plugin that might have renamed wp-ajax or something?
Because it’s far more likely that the issue is with your function not being compatible instead of the data not being sent. The data gets sent as a serialized JSON string, so unless you account for this, you’ll get errors. Once again, take a look at the Save Results Light addon for direction and examples of how to read the data, and how to safely get sanitized quiz info.
Respond to thread
You can also upload images to imgur and paste the links here. Just make sure that your images don't include any sensitive information.
Submit
Hi Dylan,
with version 1.8 of the plugin I had written a snippet that would intercept quizzes right after the answer and write some things in ACF fields if the quiz was passed at 80% or other things if the quiz was passed at 100%. Now it doesn’t work anymore.
How can I intercept in the new plugin this event?
Thanks