RESOLVED: Add input fields to end of quiz / games

hello,

I am looking to add a text field to the end of the quiz and several games so that the user can enter a name. On click of a submit button the username name and score will be stored to a wordpress DB.

I'm pretty handy with my coding I just need a starting point in the API if someone could tell me where to start looking. 

Ideal there was some end point I could hook into.

Regards 

Michael

falcon's picture

I don't know where you want to place your input field. If you add this js:

H5P.externalDispatcher.on('xAPI', function(event) {if(event.getVerb() === 'completed') {alert('completed');}});

You'll get triggered when an H5P has been completed and you may for instance display a popup where the user is to input his name.

That sounds like it may do the trick. I'll hook it up and update this post shortly.

Worked like a charm, works quite nice with jQuery UI as well. Probably would prefer it to be displayed on the result slide, So may try appending it to there instead.

Once thing though: Since I added the wordpress plugin my site will randomly die and go to browser error page but fix itself on refresh. Anyone else experienced this?

falcon's picture

We haven't experienced it. Does it only happen on pages with H5P content?

 I havn't worked out the exact parameters of when it happens. Its odd. Can't get it to  do it today.

Not to worry at the minute still havn't got replicated this today.

One last question:

Is there a way I can get the element (H5P Activity Container) that fires 'H5P.externalDispatcher.on('xAPI', function(event){}):'

Everything seems to be working just need this to future prove the scenerio  if / when there are two H5P Activities on one page. 

Sorted..

Excellent library keep up the good work

falcon's picture

Ok, you found the answers to all your questions? Good! We'll make an utility function for getting the instance when you have the contentId so that you won't have to go through H5P.instances to find it.

Yes got all my answers (for now), Now any one can save their score after finishing an activity and I can also display the latest five scores in a widget for a particular activity. Thanks for the help. Really like the library. Keep up the good work