Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Retrieve Question Labels through SmartDOMDocument?

  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 6 months ago #206680 by sodiumchl
Is there anyway to retrieve question labels this way? I tried "questions" and "labels" but could not get it to work.
Code:
$dom = new \toolsDomDocument\SmartDOMDocument();
                        $dom->loadPartialHTML($this->event->get('questions'));
                        $sLableId="ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}";
                        $input=$dom->getElementById($sLabelId);
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206688 by DenisChenu
getElementById : you get the id, not the label …

"ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}" : where did you find this id ? I don't think it exist anywhre.

Sorry : but you have to learn www.php.net/manual/en/class.domdocument.php

Here $labels = getElementsByTagName('label');
foreach $labels as label : check attribute "for" answerSGQA

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 6 months ago - 3 years 6 months ago #206740 by sodiumchl
- "ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}" : where did you find this id ? I don't think it exist anywhre.

I got it from inspecting a "Long Free Text" question, in LS v3 as below.

//type T
<div class=" question-text ">
<div id="ls-question-text-666477X2X24" class=" ls-label-question ">
My Long Free Text
</div>
</div>

<div class="ls-answers answer-item text-item ">
<textarea class="form-control " name="666477X2X24" id="answer666477X2X24"
rows="5" aria-labelledby="ls-question-text-666477X2X24"></textarea>
</div>

I would like to read/change the text "My Long Free Text" in beforeQuestionRender(). It seems toolsDomDocument should be able to do that. But what should I use in place of 'xxxxxxx' below? If you could point me to the documentation of event->get and event->set, I would greatly appreciate it.
$dom = new \toolsDomDocument\SmartDOMDocument();
$dom->loadPartialHTML($this->event->get('xxxxxxx'));
$sLableId="ls-question-text-{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}";
$input=$dom->getElementById($sLabelId);
Last edit: 3 years 6 months ago by sodiumchl.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206741 by DenisChenu
But : it's 2 different part here : ls-question-text-666477X2X24 are not part of ANSWERS in the event …

See: github.com/LimeSurvey/LimeSurvey/blob/ma...on_text_content.twig
It came from theme.

And here : it's not label tag.
See event doc : manual.limesurvey.org/BeforeQuestionRender
The event allow you to update
- aQuestion.text ( My Long Free Text)
- aQuestion.answer (<textarea … >)
- ....

maybe best is to exlain what do you want to do ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose