Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

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

surveyID, GroupID, QuestionID and others in ajax/PHP call 8 Monate 2 Wochen her #112123

  • mayeulk
  • mayeulks Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 9
  • Dank erhalten: 2
  • Karma: 1
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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

surveyID, GroupID, QuestionID and others in ajax/PHP call 8 Monate 2 Wochen her #112127

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1350
  • Dank erhalten: 319
  • Karma: 89
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

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Letzte Änderung: 8 Monate 2 Wochen her von Ben_V.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: tomscher, mayeulk

surveyID, GroupID, QuestionID and others in ajax/PHP call 8 Monate 2 Wochen her #112154

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5612
  • Dank erhalten: 323
  • Karma: 255
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)limesurvey.org'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: mayeulk

surveyID, GroupID, QuestionID and others in ajax/PHP call 8 Monate 2 Wochen her #112157

  • mayeulk
  • mayeulks Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 9
  • Dank erhalten: 2
  • Karma: 1
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: 8 Monate 2 Wochen her von mayeulk. Begründung: better code display
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.296 Sekunden
Donation Image