Passing Values from Storyline to PHP via FLASH

Iwas looking to store data from SL in external files (.txt/ .csv). Got some success via PHP calling in Storyline, both via Flash and without Flash. Here we go:

For this, we shall be using:

1.        Storyline: which will keep a Flash form to collect data

2.        A FLASH form inside the .story file: which shall collect the data and give it to PHP file

3.        PHP [no prior experience required]: This will update the collected data on the server, in form of a .txt file

Here is the workflow for the same:

 

Steps:

Step 1: Create the FLASH form in Adobe Flash or equivalent program. Let us assume, we are capturing two variables - name and email id, both of which are mandatory. On clicking the submit button, it must trigger the following code:

-----------------------------------------------------------------------------------------------

if (f1 == 1 && f2 == 1) /*Check if both name and email id are filled*/

{

var my_vars:URLVariables = new URLVariables();

my_vars.senderName = name_txt.text;

my_vars.senderEmail = mail_txt.text;

     

var my_url:URLRequest = new URLRequest("process_data.php"); /*this line calls the php file ‘process_data.php’*/

my_url.method = URLRequestMethod.POST;

my_url.data = my_vars;

     

var my_loader:URLLoader = new URLLoader();

my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

my_loader.load(my_url);

           

name_txt.text = "name";

mail_txt.text = "E-mail";

f1 = 0;

f2 = 0;

           

score=1;

ExternalInterface.call('GetPlayer().SetVar','gameScore',score);

/*Trigger the variable “score” which can be used by storyline to check if the data is submitted*/

trace(score);

}

else

{

trace("Not sent");

}

-----------------------------------------------------------------------------------------------

Step 2: Open a .story file, and insert the FLASH .swf on the first screen.

-----------------------------------------------------------------------------------------------

Step 3: Open a notepad and write the following code:

<?php

$message = "\n" . "Name: ".$_POST['senderName']. " "."E-mail : ".$_POST['senderEmail'] . "\n";

$File = "data.txt";

$Handle = fopen($File, 'a+');

fwrite($Handle, $message);

print "Data Written";

fclose($Handle);

?>

 

Save the file as “process_data.php”.

 

-----------------------------------------------------------------------------------------------

Now publish the .story file.

Step 4: Paste process_data.php in the folder where story.html is kept.

Step 5: Create a data.txt file and paste it in the folder where story.html is present.

 

And it is done! Now whenever a person fills the form and submits it. A new record is added to data.txt.

PS: What if, I want to mail the data to an email ID instead of storing it?

In the Step 3 - process_data.php, write the following code:

<?php

$to = "youremail@id.com"; /*put the recipient email id here*/

$subject = ($_POST['senderSub']);

$message = ($_POST['senderMsg']);

$message .= "\n\n---------------------------\n";

$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . " <". $_POST['senderSub']. ">\n";

$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";

if(@mail($to, $subject, $message, $headers))

{

echo "answer=ok";

}

else

{

echo "answer=error";

}

?>

Rest all the steps are same.

64 Replies
Benjamin Caulder

Benjamin Caulder said:

Kawstov FLIP said:

Benjamin Caulder said:

One last question: I have a quiz with a variable result I want to pass along to the data.csv file. It does not want to pass along, though all the other variable do (from text entries). Anyone know why?

Ben


Hi Ben,

If I refer to your example storyfile you are asking to pass it like - " Results.ScorePercent = player.GetVar("Results.ScorePercent")". Right?

Javascript may not pass inbuilt Storyline variables. Try storing the score in some another custom variable when a correct attempt is made, and then pass it via Javascript.

Regards,

Kawstov


I have been looking up how to do this, but I am not figuring this out. Does anyone have an idea?

ben


OK, so I figured this out. To pass quiz results through a javascript I had to create a number variable with the default set at zero. That variable was then entered in the javascript withe var trial = player.GetVar("trial")

From there I created a trigger that was:

Worked perfectly.

Ben

Marko Stojkovski

Hello. I am checking this, and tried to make a combination of the first two posts to create a php script that would send 3 variables to an email. So, I receive an email but with blank spaces instead of variables.

On the send email button in my storyline, I have triggered this javascript:

var player = GetPlayer();
var learner = player.GetVar("learner")
var course = player.GetVar("course")
var email = player.GetVar("email")
window.location.href = "main.php?w1="+ learner + "&w2=" + course + "&w3=" + email;

And in the main.php I have written this:

< ? php

$besked = "Student name: " .  utf8_decode($_GET['w1']). "
Student e-Mail: " . utf8_decode($_GET['w3']). "
Project name: " . utf8_decode($_GET['w2']);

print"Sending e-Mail";

// e-mail sender
$sender = utf8_decode($_GET['w3']);
 
// send e-mail
mail("elearnmarko@gmail.com", "Course Completion", $besked, "From: $sender");
?>

So I am receiveing emails on elearnmarko@gmail.com but in the body of email I got only this kind of email:


Student name:
Student e-Mail:
Project name:

Sudent name: and empty space after. I am very very bad at php and javascripting, so I basically cannot find the problem, when I have to do something with php or javascript, I am just checking around the internet and change something by logic.

Can somebody that is familiar with this show me where is my issue and how to fix it?

Thanks

Kawstov FLIP

Try this for coding your mail- 

<?php

$message ="\n" ."Learner: ".$_GET['w1']. "\n"."Email: ".$_GET['w2'] . "\n"."Project Name: ".$_GET['w3']. "\n";

echo $message;

$to = "elearnmarko@gmail.com"; 

$subject = 'Course Completion';

$headers = 'From: elearnmarko@gmail.com' . "\r\n" .

    'Reply-To: elearnmarko@gmail.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

Kawstov FLIP

And.. A slight modification:

<?php

/* $message ="\n" .$_GET['w1']. " ".$_GET['w2'] . "".$_GET['w3']. "\n"; */

$message ="\n" ."Learner: ".$_GET['w1']. "\r"."Email: ".$_GET['w2'] ."\r"."Project Name: ".$_GET['w3']. "\n";

echo $message;

$to = "your@email.com"; 

$subject = 'PHP Mail Code Test';

$headers = 'From: Your Sender Name . "\r\n" .

    'Reply-To: your@email.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

if(@mail($to, $subject, $message, $headers))

{echo "mail success";}

else

{echo "error";}

?>

Adam Love

Kawstov FLIP said:

Kennethg Goeieman said:

Hi all,

is it possible to push info from MySQL to Storyline using Javascript and PHP. I managed to store info from storyline but to push information is a hussle....any hints...

Regards

Kenneth

Hi Kenneth,

Sorry for the delayed response. There are some serious issues with the subscription to replies. To answer your query, yes it is possible. If you would have asked a month earlier, it was a no go, But just got some break-thru.

You can pull the data from MYSQL via PHP and push it in an HTML page using Javascript. This page will also contain the "SETVAR", that will push it into Storyline. When you insert the webpage as webobject, the player can recieve the values via HTML page.

Regards,

Kawstov


Hi Kawstov,

Excuse my lack of java knowledge here. So you are saying I can have a variable on a wordpress page (lets say "userfirstname", have a storyline .story file embeded into that page and pass the value of that variable to the .story file? So that I can have a slide in storyline say 'Hello "userfirstname"' ?

How would I go about this?

Adam

Kawstov FLIP

Hi Adam,

You are talking to a coding novice only

Are you trying to call the variable in a post?

Or

Changing the core files to call story output?

In both the cases, you need to push some code in the core files [index.php, etc.]. I can look into that given some time, but suggest you not to try without a PHP and Javascript prowess.

Till then some food for your thought:

http://wordpress.org/support/topic/how-to-display-username-with-published-post

Regards,

Kawstov

Linda McConnell

This is exactly what I need!! I have an orientation consisting of college facts which ends in a quiz. I need to be able to collect the quiz data and send it via email without the ability of the user manipulating the information. We don't want to use an LMS since we don't want to create student accounts we just want to be able to tell folks to go to this website, go through the orientation, take an exam and that's it for them. Then on our side we want to know they visited all sections, completed the exam with what score, and the first/last name of whomever took the exam.

Is this possible with what you are describing here?

Linda

Kawstov FLIP

Linda McConnell said:

This is exactly what I need!! I have an orientation consisting of college facts which ends in a quiz. I need to be able to collect the quiz data and send it via email without the ability of the user manipulating the information. We don't want to use an LMS since we don't want to create student accounts we just want to be able to tell folks to go to this website, go through the orientation, take an exam and that's it for them. Then on our side we want to know they visited all sections, completed the exam with what score, and the first/last name of whomever took the exam.

Is this possible with what you are describing here?

Linda


Absolutely Linda,

If u have Flash skills to insert the code, this is what u need.

Even if you don't have Flash know how, you can carry on like this.

If the test is a serious one and you don't want students to mess around with the score, you can use this method

Regards,

Kawstov

Kawstov FLIP

Kennethg Goeieman said:

Kawstov FLIP said:

Hi Kennethg,

I am fine, thanks!

Are you asking to go back from PHP to Storyline ?

Yes it is possible. You will have to insert the HTML tag.

Please refer here.

Regards,

Kawstov


Hi,

Link is not available


Hi Kenneth, sorry for the trouble but link is working alright.

Here is the absolute path:

http://blog.kawstov.com/passing-values-from-html-to-storyline/

Regards,

Kawstov

Doug Brown

Aunt Bee said:

Here the issue is security.  If the URL pushed from PHP code contains values, those values can be changed.  How to work around that? 


Hi , are you referring to data coming into Storyline or going out to a database?

All code can be hacked including LMS data transfers like Moodle but simple measures can make it harder for the average user.

Can you be more specific on the security issue you are referring to?

Regards

Doug

Kawstov FLIP

Aunt Bee said:

Here the issue is security.  If the URL pushed from PHP code contains values, those values can be changed.  How to work around that? 


Hi Aunt Bee,

The only front end loop hole I see, is while pushing the data from SL to PHP.

That can be solved. Please refer  - http://blog.kawstov.com/storyline-to-php-via-ajax/

Rest all needs special skills to crack.

Jon Gledhill

This is absolutely fantastic! I'm using "passing via PHP to a txt file" and it works great.

One issue I have though is that when the form is submitted the user is taken out of the Storyline presentation and shown the confirmation words in the same browser window.

Is there a way to submit the variables to the txt file and for the user to move on to a final storyline page telling them their results have been submitted?

I've been trying to figure out how to get the php to open up in a new blank browser window and also get the articulate storyline project to advance to the next slide so they can close the confirmation window and continue with the storyline course. 

In a perfect world they wouldn't see the confirmation page a t all but just continue to the next slide in Storyline but i am aware that the PHP page needs to open in order for the variables to be recorded in the text file.

I could really use some help on this one as I've very little php and javascript knowledge.

Thanks

Jon

Kawstov FLIP

Hi Jon,

 

Sorry for the late reply.

Yes the reverse data flow [from html to SL] is also possible.

Here's a post that can help u:

http://blog.kawstov.com/passing-values-from-html-to-storyline/

 

Two things to care about - 

1. Add the HTML as web page

2. Add a variable is SL that can be changed by HTML [method discussed in post]. Then put a trigger in SL that jumps to next slide, when the variable changes.

 

Do reply how u used it. :)

Regards,

Kawstov

nai p.

Hi Kawstov,

First of all, thanks so much for sharing your insights about all these techie variable parsing. It's just what I need for my project!!

I went through both of your postings:  parsing values from flash to php and from storyline to PHP via javascript. I'm not a technical person, and barely understood half of what you put up there, but thanks to your sample code, I finally managed to get things work (both emailing the variables and writing them on the designated file). However there are still some issues and a few things I still need to have adjusted, but I can't seem to find references on how to. I really hope you will be able to help me out, or point me to the right directions. 

First, pls let me describe my situation.

OBJECTIVES:
to email values from a Storyline lesson as well as write them on a file located on a server WITHOUT disconnecting the learner from the lesson slide (without loading a new page).

ABOUT THE PROJECT:  (It's just a simple 1-page version just to test functionality -- I've attached the file here

>> A storyline page with few variables, but the 2 variables, "result1" and "result2", are to be passed.

>> once the user clicks the "See Results" button, the 2 results should be calculated and displayed on the slide  AND AT THE SAME TIME the values should be sent to an email and written on a file. 

NOTES: I would like the parsing of values to be done without causing any interruption to the user's current interaction with Sloryline lesson. In other words, there shouldn't be any refreshing or reloading of the browser.

WHAT I'VE DONE: 

>> I put 'execute javascript' as the last trigger of the "See Results" button.  (I assume it works since I get the values sent to my email and recorded on the csv file).

=== this is the adjusted javascript code I added in Storyline ====

var player = GetPlayer();

var result1 = player.GetVar("result1")
var result2 = player.GetVar("result2")


window.location.href = "http://www.myurl.com/testjscript/process.php?w1=" + result1 + "&w2=" + result2;

=== this is the adjusted php code for EMAILING and STORING variables  (I combined them)===

<?php

$cvsData .= $_GET['w1'].",".$_GET['w2'].",".PHP_EOL; // Format to concatenate the data in one string.

$fp = fopen("data.csv", "a");

if($fp)

{

fwrite($fp,$cvsData); // Write information to the file

fclose($fp); // Close the file

}

 

/* $message ="n" .$_GET['w1']. "".$_GET['w2']. "n"; */
$message ="n" ."RESULT 1 = ".$_GET['w1']. "r"."RESULT 2= ".$_GET['w2']. "n";

echo "Thank You!";

$to = "contact@myurl.com";

$subject = 'PHP Mail Code Test';
$headers = 'From: abcxyz.com' . "rn" .
'Reply-To: anemail@email.com' . "rn" .
'X-Mailer: PHP/' . phpversion();

if(@mail($to, $subject, $message, $headers))
{echo "mail success";}
else
{echo "error";}

?>

 

PROBLEMS:

After clicking the "See Results" button, the javascript gets executed and the window is refreshed to a new page with the echo text (in this case it's the "Thank You! mail success"). That means the user is disconnected from the lesson.

 ===> Is there any way that we can avoid that? I need the user to stay at the lesson and still can continue interacting with storyline.

OTHER ISSUES:

* The headers on the email that php sends are as shown below.  The "From:" looks kind of confusing with everything comes together in one chunk.

From: abcxyz.comrnReply-To:anemail@email.comrnx-mailer
To: contact@myurl.com

 

 ===> Did I make any mistake in the PHP?

* These are the results I got on the mail.  There are "n" and "r" everywhere.

nRESULT 1 = 100rRESULT 2= 99n

 

===>I guess I need to remove the "n" and "r" from the code,right?

 

Thank you so so much in advance for your time and help!!

Naiyana

 

Kennethg Goeieman

My problem,

I have a client with  a learners dbase. We have different quizzes assigned for different learners. Learners will login by entering their ID number on the storyline start screen. is there a way I can push that variable into a SQL dbase and then push back the rest of the information to storyline.

 Please help..ANYONE!

ubong ekpo

Hello Kastaw and thanks for this. Been looking for something similr for a while on how to export the essaytype answers from storyline to some location or have them emailed so they can be reviewed and marked for an anuual test as we are not using multiple choice.

I prefer the javascript approach but your step 1 is:

Step1: Create a trigger to execute a javascript when submit button is clicked

Enter the Javascript:

Where do I enter this javascript and how do I do it for the entire quiz to export the essay type answers.  The example seems to be for a single form? Would appreciate your assistance.

Yubi

Dmitry Chabanenko
nai p.

Hi Kawstov,

First of all, thanks so much for sharing your insights about all these techie variable parsing. It's just what I need for my project!!

I went through both of your postings:  parsing values from flash to php and from storyline to PHP via javascript. I'm not a technical person, and barely understood half of what you put up there, but thanks to your sample code, I finally managed to get things work (both emailing the variables and writing them on the designated file). However there are still some issues and a few things I still need to have adjusted, but I can't seem to find references on how to. I really hope you will be able to help me out, or point me to the right directions. 

First, pls let me describe my situation.

OBJECTIVES:
to email values from a Storyline lesson as well as write them on a file located on a server WITHOUT disconnecting the learner from the lesson slide (without loading a new page).

ABOUT THE PROJECT:  (It's just a simple 1-page version just to test functionality -- I've attached the file here

>> A storyline page with few variables, but the 2 variables, "result1" and "result2", are to be passed.

>> once the user clicks the "See Results" button, the 2 results should be calculated and displayed on the slide  AND AT THE SAME TIME the values should be sent to an email and written on a file. 

NOTES: I would like the parsing of values to be done without causing any interruption to the user's current interaction with Sloryline lesson. In other words, there shouldn't be any refreshing or reloading of the browser.

WHAT I'VE DONE: 

>> I put 'execute javascript' as the last trigger of the "See Results" button.  (I assume it works since I get the values sent to my email and recorded on the csv file).

=== this is the adjusted javascript code I added in Storyline ====

var player = GetPlayer();

var result1 = player.GetVar("result1")
var result2 = player.GetVar("result2")


window.location.href = "http://www.myurl.com/testjscript/process.php?w1=" + result1 + "&w2=" + result2;

=== this is the adjusted php code for EMAILING and STORING variables  (I combined them)===

<?php

$cvsData .= $_GET['w1'].",".$_GET['w2'].",".PHP_EOL; // Format to concatenate the data in one string.

$fp = fopen("data.csv", "a");

if($fp)

{

fwrite($fp,$cvsData); // Write information to the file

fclose($fp); // Close the file

}

 

/* $message ="n" .$_GET['w1']. "".$_GET['w2']. "n"; */
$message ="n" ."RESULT 1 = ".$_GET['w1']. "r"."RESULT 2= ".$_GET['w2']. "n";

echo "Thank You!";

$to = "contact@myurl.com";

$subject = 'PHP Mail Code Test';
$headers = 'From: abcxyz.com' . "rn" .
'Reply-To: anemail@email.com' . "rn" .
'X-Mailer: PHP/' . phpversion();

if(@mail($to, $subject, $message, $headers))
{echo "mail success";}
else
{echo "error";}

?>

 

PROBLEMS:

After clicking the "See Results" button, the javascript gets executed and the window is refreshed to a new page with the echo text (in this case it's the "Thank You! mail success"). That means the user is disconnected from the lesson.

 ===> Is there any way that we can avoid that? I need the user to stay at the lesson and still can continue interacting with storyline.

OTHER ISSUES:

* The headers on the email that php sends are as shown below.  The "From:" looks kind of confusing with everything comes together in one chunk.

From: abcxyz.comrnReply-To:anemail@email.comrnx-mailer
To: contact@myurl.com

 

 ===> Did I make any mistake in the PHP?

* These are the results I got on the mail.  There are "n" and "r" everywhere.

nRESULT 1 = 100rRESULT 2= 99n

 

===>I guess I need to remove the "n" and "r" from the code,right?

 

Thank you so so much in advance for your time and help!!

Naiyana

 

Hello! Did you find the error in your code?