Welcome to the LimeSurvey Community Forum

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

Best way to echo content in a survey for a plugin

  • teonline
  • teonline's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago - 7 years 1 month ago #150785 by teonline
Recently I found out that LimeSurvey allows you to create plugins. It is so much better to add a functionality via a Plugin than hacking everything in some broken Frontend-JS that will be injected into the survey...

Long story short: I got the plugin working, but there are still some things that I'd wish to be better / easier.

I'll start in this post with my most pressing issue. The plugin in question shows a generated link at the end of each survey it got activated for in the survey settings.

I'm using this code inside the callback for the event "afterSurveyComplete" to show the link when a user configured it to show up:
Code:
$event->getContent($this)->addContent('<a href="' . $url . '">' . $linkText . '</a>');

However, the link will be displayed above the end message for the survey. There is a constant to choose between append and prepend for "addContent", but it does only refer to the order related to other plugin's output. From what I see there is no possibility to echo content after the end message, right?

Maybe another event-hook should be added there, I don't know.

I kind of solved the problem by introducing an alternative end message that would be displayed before the generated link. To enable a user to edit this message I added a field in my plugin settings for the survey like this in the "beforeSurveySettings" event-hook:
Code:
      $event = $this->getEvent();
      $event->set("surveysettings.{$this->id}", array(
        'name' => get_class($this),
        'settings' => array(
          'prependSurveyEndText' => array(
            'type' => 'html',
            'default' => '',
            'label' => 'Show this text as alternative endmessage',
            'current' => $this->get('prependSurveyEndText', 'Survey', $event->get('survey'))
          )
        )
      ));

Unfortunately, this solves one problem, but introduces two more problems. Firstly, the editor doesn't render correctly (it's only a very basic editor without a toolbar like the other htmleditors). Secondly, the default end message for the survey needs to be "edited empty". The user needs to add some HTML that includes a non-visible character, because with an entirely empty end message in the survey, the default LimeSurvey end message would show up.

The coolest thing would be, if plugin developers could register text variables that would be replaced at runtime. But I don't see any such possibility right now. E.g. in this case I could simply declare a new text variable like CUSTOM_LINK and a user could insert it into the default end message HTML editor, while it would be replaced when loading the page.

Are there any ideas of how to overcome the challenges I'm facing with this plugin or any suggestions on how to implement a replace variable?

I would be glad for any suggestions :-)
Last edit: 7 years 1 month ago by teonline.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #150822 by DenisChenu
Replied by DenisChenu on topic Best way to echo content in a survey for a plugin
If i remind : i make the bug report a long time ago , beause addContent muts allow content to be before OR after core content.

But now : i directly use my own content : extensions.sondages.pro/development-and-...-part-rendermessage/

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 following user(s) said Thank You: teonline
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose