Explore the community Forums Lectora Lectora Questions & Answers Passing a Lectora Variable to an External HTML Object (PHP)

Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #300859 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    profile
    12 pts
    @mlapl1

    Another PHP issue.

    I have created an External HTML object using PHP. I want to send a Lectora variable to the PHP script for processing. I have associated with the External HTML Objecta a Lectora variable using the Required Variable TAB.

    My problem is that I can find no way of accessing the variable using php.

    Any thoughts gratefully accepted

    Andrew

    • This topic was modified 3 years, 9 months ago by Profile photo of Andrew Lian Andrew Lian.
    #300869 Score: 1
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    302 pts
    @timk

    The only way (I know) to do that is by submitting a form or a test. Just create a form with no form elements. Check “Include ALL variables (Test and Title)” in the Submission settings of the form. In the “Data Submission” group Check “Submit form” “Submit to: Custom Script”, then click “Settings” and enter the URL of your script.

    You can now send your variables with a “Submit Form” action.

    Tim

    This post has received 1 vote up.
    #300870 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    117 pts
    @mnotermans5114

    With Javascript it would be simple: VarMyVariableName.getValue();

    Using the Var in front of the actual variable name. I suppose something like that will do for PHP too…

    Actually that might be the clue.. do not try and send it from Lectora, but get it from PHP…

    #300880 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    profile
    12 pts
    @mlapl1

    Thank you Tim and Math,

    Just to be clear. A so-called “external html object” is actually generated within a lectora file – so it is not really external (i.e. a separate external file though it can include one somehow). Second, it also has a setting for including what they called “Required Variables”. I am wondering what that could possible mean. I have identified such a variable for a PHP “external html object”. If I inspect the .php file generated by Lectora I can actually see a JavaScript statement defining the variable I want to include.

    The PHP component of the file is actually between a <DIV> </DIV> statement – but of course I cannot transfer the variable from the JS section to the PHP section.

    Maybe I will actually have to do a get from the PHP section (at least simulate one) – or even use a truly external PHP file to achieve what I need to do.

    I guess my point is: If it is so difficult to get JS to talk to PHP, what is the point of having the “Required Variables” option for an “external html object”. Unfortunately the user manual is not very helpful on this topic.

    Thanks again

    Andrew

    #300885 Score: 1
    Profile photo of Sergey Snegirev
    Sergey Snegirev
    Member
    contributor
    intermediate
    advanced
    friend finder
    lab member
    junior moderator
    advocate
    LUC16
    LUC16 Attendee
    wise owl
    335 pts
    @ssneg

    Lectora variables are normal javascript front-end client-side variables. In order to pass one to a back-end server-side PHP script, you need to submit it via a POST/GET request.

    The easiest (as in, writing less code) way to do so is to submit all variable values at once with a form or quiz results (step-by-step). You will just need to provide the URL of your PHP script that processes the request.

    This post has received 1 vote up.
    #300892 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    profile
    12 pts
    @mlapl1

    Yes I get it but then why have an option for what they call “Required variables”. I guess I was just hoping they had built-in some of this so as to say work – especially as I see the variable declaration in the php file BUT in the JS area of the file.

    #300942 Score: 1
    Profile photo of Sergey Snegirev
    Sergey Snegirev
    Member
    contributor
    intermediate
    advanced
    friend finder
    lab member
    junior moderator
    advocate
    LUC16
    LUC16 Attendee
    wise owl
    335 pts
    @ssneg

    In Lectora Inspire/Publisher, none of your custom variables are created and initiated by default so their values cannot be accessed via JS. You have to do at least one of two things to make Lectora initialize the variables:
    a) use them in an action or expression on the page
    b) set them as “Required” for an object in the page

    I usually choose the latter option because it seems more logical. If scripts in my Ext HTML object use a variable then this variable must be set as Required in that object’s properties. It also has a benefit of carrying over from title to title, so if I copy the Object from one title to another, the required variables are carried over with it (I think).

    P.S. None of the above applies to Lectora Online where all and any custom variables are initialized on every page by default so you don’t have to think about it twice.

    This post has received 1 vote up.
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.