Welcome, Guest
Username: Password: Remember me

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

surveyID, GroupID, QuestionID and others in ajax/PHP call 2 months 3 weeks ago #112123

  • mayeulk
  • mayeulk's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Thank you received: 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
The administrator has disabled public write access.

surveyID, GroupID, QuestionID and others in ajax/PHP call 2 months 3 weeks ago #112127

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1147
  • Thank you received: 273
  • Karma: 79
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...
Last Edit: 2 months 3 weeks ago by Ben_V.
The administrator has disabled public write access.
The following user(s) said Thank You: tomscher, mayeulk

surveyID, GroupID, QuestionID and others in ajax/PHP call 2 months 2 weeks ago #112154

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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'"
The administrator has disabled public write access.
The following user(s) said Thank You: mayeulk

surveyID, GroupID, QuestionID and others in ajax/PHP call 2 months 2 weeks ago #112157

  • mayeulk
  • mayeulk's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Thank you received: 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
Last Edit: 2 months 2 weeks ago by mayeulk. Reason: better code display
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.272 seconds
Donation Image