To start with, let us assume that we need to store data from a Feedback Form in Storyline.
The variables created in the Storyline are: ‘name’, ‘rating’ and ‘comment’.
var player = GetPlayer();
var name = player.GetVar(“name”)
var rating = player.GetVar(“rating”)
var comment = player.GetVar(“comment”)
window.location.href = “http://yoururl.com/feedback/main.php?w1=” + name + “&w2=” + rating + “&w3=” + comment;
Explanation of the last line:
The last line redirects the current window to the location where the PHP is kept (http://yoururl.com/feedback/) and pushes the values of name, rating and comment as w1, w2 and w3 respectively into the PHP.
In case, you need to push another variable (say w4 – for email): just add
+ “&w4=” + email
Step 2: Create the PHP (main.php) at the url given (http://yoururl.com/feedback/)
Enter the code:
For saving data in a .txt file:
$message = “n” .$_GET[‘w1’]. ” “.$_GET[‘w2’] . ” “.$_GET[‘w3’]. “n”;
$File = “data.txt”;
$Handle = fopen($File, ‘a+’);
print “Data Written”;
Also create data.txt file and save it at the location of main.php.
For saving data in a .csv file:
$cvsData .= $_GET[‘w1’].”,”.$_GET[‘w2’].”,”.$_GET[‘w3’].”,”.PHP_EOL; // Format to concatenate the data in one string.
$fp = fopen(“data.csv”, “a”);
fwrite($fp,$cvsData); // Write information to the file
fclose($fp); // Close the file
Also create data.csv file and save it at the location of main.php.
Now publish the .story file and upload it. This time*, there is no need to keep the data file (.txt/.csv) in the same folder where story.html is kept.
You can find the source files here.