surveyID, GroupID, QuestionID and others in ajax/PHP call

Mehr
2 Jahre 10 Monate her #112123 von mayeulk01
mayeulk01 erstellte das Thema surveyID, GroupID, QuestionID and others in ajax/PHP call
Hello,
For keywords in the template files, there is nothing for the SurveyID (the long number as 762974). Also, the groupid can be inferred from the SGQ code such as 762974X13X51, but the SGQ code is not working in startgroup.pstpl
Are there other ways to get other variables than the one sent in AJAX call from a Limesurvey Keyword in a template? Including the token, the group id (within startgroup.pstpl)?

Below is how I try to get some of these parameters with AJAX interaction (not working yet though), using some regular expression

Within question.pstpl:
<div id="question_history_ajax_script">
    <script type="text/javascript" charset="utf-8">
 
    // Identify the current script element NOTE: must be before $(document).ready(function()
    var scripts = document.getElementsByTagName('script');
    var thisScript = scripts[scripts.length - 1];
 
    $(document).ready(function() {
 
        // Identify the current script's parent element
        var scriptParent = $(thisScript).parent();
 
        // Pull in the remote file
        $.ajax({
            type: "GET",
            url: '{TEMPLATEURL}lime_question_history.php',
            data: 'country={TOKEN:ATTRIBUTE_8}, role={TOKEN:ATTRIBUTE_1},  sqg={SGQ}',
            success: function(results){
                // Load the remote file contents into the script parent element
                $(scriptParent).append(results);
            }
        });
    });
 
</script>
</div>

<?php
$sgq = $_GET['sqg'];
 
if(preg_match('(\d+)X(\d+)X(\d+)',$str,$matches)) {
   $surveyid = $matches[1];
   $groupid = $matches[2];
   $question = $matches[3];
}
?>

Note, again, that I would like some of this in the EndGroup group template too.

Pointers in the manual, forum (or if absolutely needed source code in GitHub) would be appreciated.
Thank you!
Cheers,
Mayeul

Bitte Anmelden um der Konversation beizutretten.

Mehr
2 Jahre 10 Monate her - 2 Jahre 10 Monate her #112127 von Ben_V
Ben_V antwortete auf das Thema: surveyID, GroupID, QuestionID and others in ajax/PHP call
Hi,
the most of the time the following {keywords} do the trick:

Survey ID: {SID}
Group ID: {GID}
Question ID: {QID}

(Old "SGQ code such as 762974X13X51" can be retrieved using {SID}X{GID}X{QID} syntax or {SGQ} placeholder )

To go further or check if a {keyword} is allowed in a specific template file, you can have a look at EM Roadmap
.

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Letzte Änderung: 2 Jahre 10 Monate her von Ben_V.
Folgende Benutzer bedankten sich: tomscher, mayeulk01

Bitte Anmelden um der Konversation beizutretten.

Mehr
2 Jahre 10 Monate her #112154 von Mazi
Mazi antwortete auf das Thema: surveyID, GroupID, QuestionID and others in ajax/PHP call
If some of the above placeholders don't work at certain template files, you can try to make use of some of the hidden INPUT elements Limesurvey uses.

When checking the source code of any question page you should find elements like:

<input type="hidden" name="fieldnames" value="157348X205X1087|157348X205X1037|157348X205X1038" id="fieldnames">

<input type="hidden" name="sid" value="157348" id="sid">

<input type='hidden' name='lastgroup' value='157348X205' id='lastgroup' />

<input type="hidden" name="token" value="12345" id="token">

Especially the first one should help you dealing with any question on the current page.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
Folgende Benutzer bedankten sich: mayeulk01

Bitte Anmelden um der Konversation beizutretten.

Mehr
2 Jahre 10 Monate her - 2 Jahre 10 Monate her #112157 von mayeulk01
mayeulk01 antwortete auf das Thema: surveyID, GroupID, QuestionID and others in ajax/PHP call
Thank you both! This works well:
<div id="show_group_history_ajax_script">
    <script type="text/javascript" charset="utf-8">
    // Identify the current script element NOTE: must be before $(document).ready(function()
    var scripts = document.getElementsByTagName('script');
    var thisScript = scripts[scripts.length - 1];
    $(document).ready(function() {
        // Identify the current script's parent element
        var scriptParent = $(thisScript).parent();
        // Pull in the remote file
        $.ajax({
            type: "POST",
            url: '{TEMPLATEURL}show_group_history.php',
            data: 'country={TOKEN:ATTRIBUTE_8}&role={TOKEN:ATTRIBUTE_1}&token={TOKEN}&surveyid={SID}&groupid={GID}',
            error: function(xhr, status, error) { // http://stackoverflow.com/questions/1637019/how-to-get-the-jquery-ajax-error-response-text
	      var err = eval("(" + xhr.responseText + ")");
	      alert(err.Message);
	    },
            success: function(results){
                // Load the remote file contents into the script parent element
                $(scriptParent).append(results);
            }
        });
    });
 
</script>
</div>
Mayeul
Letzte Änderung: 2 Jahre 10 Monate her von mayeulk01. Begründung: better code display

Bitte Anmelden um der Konversation beizutretten.

Haben Sie schon bei unserer Kundenumfrage mitgemacht?

Verpassen Sie nicht Ihre Chance auf tolle Preise.

Klicken sie hier um teilzunehmen:

Jetzt starten

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten