Passing Values from Storyline to PHP via FLASH

Aug 13, 2013

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
nai p.

I don't have the files with me. but if you can wait till weekend, I can go check it for you. will that help? also I'm not sure if It's the exact solution, I believe I sort of improvised something. but in the end i got the results sent to my email. anyway, pls just let me know if you need me to look for the code this weekend.

nai p.

Hi there,

OK, I've got the files.  See the attached files.

I deleted all other slides on the file and left the most important one that you need, which is the slide that is used to process all the data. I don't remember details anymore, but I'll try my best giving you some summary to help you see how these files work together.

(Notes + disclaimers :-) the orginal solution was suggested by Kawstov, and I believe I've been digging in and got some other solution and sort of mixed and matched things together. So the code will look messy for any real programmer, but at least it works for me.


In General, this solution sends data in the following manner (as far as I understand)
Articulte ==> .html ==> .php ==> email and/or .cvs file on server

Here are the files that will need to be working together

  • Articulate file: - with a text entry box for email inputing - with an .html object embeded and points to the URL where the corresponding .html file is
  • .html - with filename as specified in the .html object in Articulate file - with all the variables/data spelled out and the name of .php file specified in the code --- see the code
  • .php - here is where you say which variables will get sent to where - email and/or written on .cvs
  • .cvs - must have the name as specified in .php 

FILE Locations:
I put all those 4 files (the story.html, the data-processing html file, the .php file, and the .cvs file) in the same location. (I believe you can put them in different locations as long as you specify the paths correctly----but again, I'm not sure, please just try.)

I hope that helps & good luck!
n.

Kennethg Goeieman

Hi nai P

Great work.... 

I would like to know is there a way one can pass a value through to  database as you did here and then return from a database other values which you can set variables in storyline.

Basically, what I want to ask is, if its possible to set variables via .php /html to storyline.

would greatly appreciate....

 

nai p.

Hi Kennethg,

I have never done it the other way (passing values from .php/html to storyline), but maybe will use that in the future. So I did a quick seach and found the link here. I haven't read details but from the first glance, it may address your need. So please check it out!

https://community.articulate.com/discussions/articulate-storyline/passing-values-into-storyline

nai.

Abhishek Roy

can anyone help me urgently ? i followed nai p. workaround to send email through styoryline using html + php . it works perfectly when published as Web and uploaded to a web server.

But it's not working when published as LMS . i have uploaded the package to Moodle 2.6 . i can't receive any email.

the asme package when published as Web is sending email perfectly.

i need some workaround asap.

attached : story file, html file to pass value, php file to send email and the error from debug console.

i'm publishing it as SCORM 1.2

i have uploaded it to both moodle and scorm cloud. same error.

error :

GET
https://cloud.scorm.com/content/courses/LZULP05G1Q/Storyline2Emailviacb88e172-d9b5-44e1-b6e6-56126002ad0a/0/story_content/WebObjects/5tUezNpTlTN/FILENAME_passvalues.html [HTTP/1.1 200 OK 835ms]
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/ FILENAME_passvalues.html:35:0
GET
XHR
https://cloud.scorm.com/content/courses/LZULP05G1Q/Storyline2Emailviacb88e172-d9b5-44e1-b6e6-56126002ad0a/0/story_content/WebObjects/5tUezNpTlTN/FILENAME.php [0ms]
GET
https://cloud.scorm.com/content/courses/LZULP05G1Q/Storyline2Emailviacb88e172-d9b5-44e1-b6e6-56126002ad0a/0/story_content/blank.html [HTTP/1.1 200 OK 1702ms]
NS_ERROR_FAILURE:

thanks.

Kawstov Singh
nai p.

Hi, i wish i could help. But what i did was passing data from flash to php and from php to a text file. I don't know how to convert it to pdf. I am sorry. I hope you could get help from someone else soon.
best

Hi All (and Nai),

Sorry for not replying so long.

I see that you need JS to PDF in SL.

I suppose this might help

http://blog.kawstov.com/export-data-from-storyline-to-pdf/

 

Feel free to ask in case you need anything.

 

Regards,

Kawstov

Kawstov Singh
nai p.

Hi Kennethg,

I have never done it the other way (passing values from .php/html to storyline), but maybe will use that in the future. So I did a quick seach and found the link here. I haven't read details but from the first glance, it may address your need. So please check it out!

https://community.articulate.com/discussions/articulate-storyline/passing-values-into-storyline

nai.

I think I worked on this as well:

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

 

Feel free to ask in case of any queries.

Sorry again for replying late guys.

 

Regards,

Kawstov

This discussion is closed. You can start a new discussion or contact Articulate Support.