Passing Moodle Variables to SCORM content

Passing Moodle Variables to SCORM content

by Scott Karren -
Number of replies: 2

Everyone,

We are currently using Moodle 2.6.5+ and Articulate Studio 13 (Update 5) to publish SCORM content.  In some of this content I have embedded javascript as Articulate web objects to capture the students email address. 

Basically, the student starts the SCORM presentation, the first slide asks them to enter their email address, the email address is used as an identifier in subsequent slides.

I would like to know if there is a way to capture the students email address from Moodle so they don't have to enter it.  Is there anyone out there doing this currently?  If so would you be willing to share your code?

Here is the current javascript code I use to have the student enter their email address.

<script type="text/javascript">
 
function saveEmail(){
     window.parent.emailaddy = document.myform.email.value;
        if (window.parent.emailaddy == null || window.parent.emailaddy == "") {
        alert("Email address must be filled out");
        return false;
        }
            window.parent.emailaddy = document.myform.email.value;
            var atpos = window.parent.emailaddy.indexOf("@");
            var dotpos = window.parent.emailaddy.lastIndexOf(".");
            if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=window.parent.emailaddy.length) {
                alert("Not a valid e-mail address");
                return false;
    }
       
        alert("Email successfully submitted. Close this window and click Next to continue");
    console.log('saveEmail '+window.parent.emailaddy)
}
</script>
</head>
<body>

<form class="form" name="myform" action="" method="get">
Enter your email address in the box: <br>
<input class="input" type="text" name="email" value="">
<INPUT class="button" TYPE="button" NAME="button" Value="Submit" onClick="saveEmail()">
</form>


Scott

Average of ratings: -
In reply to Scott Karren

Re: Passing Moodle Variables to SCORM content

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
The SCORM var cmi.core.student_id contains the Moodle username so if you are using e-mail address as your Moodle username you could use that - if not you could modify the Moodle code to pass the $USER->email instead of $USER->username here:
https://github.com/moodle/moodle/blob/MOODLE_26_STABLE/mod/scorm/loaddatamodel.php#L67
In reply to Dan Marsden

Re: Passing Moodle Variables to SCORM content

by Scott Karren -

Dan,

Thanks for the reply.  Am I limited to SCORM variables within the course?  I guess I am asking if there is a way to pull the users email address into the SCORM or if I can only use the variables that SCORM has available?

If I can only use the variables that SCORM has available how would changing the code to pass email affect things like grade reporting?

Scott