send survey results to database

mbuitenkamp-4316
mbuitenkamp-4316 Community Member Posts: 14 ☆ Roadie ☆
Hi,

I really hope someone can help me:

I have a survey with quite a number of variables that I want to send to a mySQL database.
All I can find is that I apparently need to use a custom script and use POST, but to me, that's hocus pocus.

Can anyone help me get all my variables into my database?
Here's a few of my variables:

var_Name
var_DOB
var_City

Thanks in advance x

Answers

  • wheels
    wheels Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 595 eLearning ROCKSTAR Admin Team
    Hi @mbuitenkamp-4316

    From the Lectora side it is pretty straight forward.

    Here are two options:

    Insert a form.
    1. Insert a Lectora Form object from the Test & Survey ribbon.
    2. In the Form properties select Submit Form, Custom Script, then add the URL where the form should be posted to.
    3. Insert Entry Fields, also on the T&S Ribbon, into the Form.
    4. Name the entry fields in the Project Explorer so they match what the server expects.
    5. Set the entry field variables to your variables.
    6. Add an Action either on show, or on click of a button, with an action of Submit Form for this form.
    Use a jQuery script

    Your other option is to use Lectora's built in jQuery object triv$ to submit your variables.

    For this method just create an Action that has the action Run JavaScript and add the following code (modified for your purposes):
    
    triv$.post('https://server.com/url-for-the-post',
                {
                    'name' : Varvar_Name.getValue(),
                    'dob'   : Varvar_DOB.getValue(),
                    'city'    : Varvar_City.getValue()
                }
    );
    
    The parameters consist of the parameter name expected on the server such as 'name' and then the value of your variable. The JavaScript name of the variable is your variable name var_Name prefixed with Var. The getValue function returns the current value to send to the server.

    For the server side you might consider hiring a contractor on Upwork or a similar site.

    Another option might be to sign up for Airtable and build your database, it's fairly simple point and click. Then after you have created it they give you an API that you could modify and call easily with the second method above (Run JavaScript).

    Here is an example for posting data to Airtable, and I'm sure a little searching can find better ones. Use the getValue() method above to get the values from your variables..