0

I'm creating a system on D7 that tracks how much progress users have made watching various videos on the site. I've set up the jQuery that stores the percentage progress in an array with a modified version of the process at https://www.urbaninsight.com/2014/10/06/tracking-progress-embedded-vimeo-videos. Where I'm lost is where I actually post the data using:

$.post('/callback', { progress: myProgressVariable });

I realized that '/callback' is just a placeholder, but I don't know what to sub in there. Should I designate a callback() function in a custom module that does something with the progress data and just place the function name into the javascript -- and what might that look like? Or do I need to do something something else entirely?

4
  • The counterpart for the callback in Drupal would be a Controller defined in a route (or the hook in D7 that can do anything, not only menus). But better deliver the content in a form and trigger the submit, this is more secure.
    – 4uk4
    Commented Nov 1, 2017 at 8:34
  • So if the best way is to deliver the data via a form, how would I get the data from my jQuery object into the form if the form doesn't live on the active page? I'm assuming that the form doesn't need to be on the active page. I'd rather not have it there, actually, so that users couldn't manually submit values if they found it.
    – Mrweiner
    Commented Nov 1, 2017 at 18:47
  • You can approach this from three sides. 1) Use the form api which includes the built-in mechanism to handle the form submits. You can hide the form if you want to keep it in the background. 2) Define your own controller and handle the post data yourself (which is IMHO more work to do if you want to do it right). 3) Keep Drupal out of it and use a standalone php file as callback.
    – 4uk4
    Commented Nov 1, 2017 at 19:37
  • I see you've added a D7 tag. The concept there was the same, you have to assign a php function to the path /callback and then check what post data comes in. What the php function returns doesn't matter, because your js code ignores it.
    – 4uk4
    Commented Nov 1, 2017 at 19:51

1 Answer 1

0

Ended up just using a custom hidden form as suggested by 4k4 and am populating/submitting it via jquery/ajax.

Your Answer

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

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