1

Topic: Survey Generator Plugin

Hi everyone, I converted a stand-alone application I had previously developed into a Wolf plugin to learn how the plugin system works.

The plugin lets you conduct custom surveys that you design. It also summarizes the results for you. The plugin does not use a database. Instead, the survey definitions are stored in text files in a basic INI format. The responses are collected in a CSV file. Both the definition and response files go in the public directory. The plugin's online documentation explains this in detail.

After installing the plugin,

To conduct a survey:
<?php survey_conduct('survey_definition_file'); ?>

To summarize the responses to a survey:
<?php survey_summarize('survey_definition_file'): ?>

I've placed the plugin here.
http://www.clicketyhome.com/survey-plug … lf-CMS.zip

Thank you for trying it out and leaving any feedback about it!

EDIT: Oops, forgot the license. It's GPL 3.0 of course. Also, I'll put it on GitHub later.

Last edited by RobertH (2015-08-31 02:32)

Thumbs up +1

2

Re: Survey Generator Plugin

Hi Robert - thanks for this! Looks like it could be very useful.

Looks like there's a documentation problem. wink the online docs say:

To conduct the survey within a Wolf CMS page, you would place the following code in the page.

<?php if (Plugin::isEnabled('survey')) survey('my_survey'); ?>

In your post above, the correct syntax is given as:

<?php if (Plugin::isEnabled('survey')) survey_conduct('my_survey'); ?>

I.e., "survey_conduct()", not simply "survey()".

Also, the docs say there should be a "sample-survey" file included in the Zip, but it seems to have been omitted.

Update: now the survey is showing, but no check-boxes to record responses are generated. Any thoughts on that one? As it happens, it's working perfectly on the other site. I see that there's CSS applied, and that this doesn't seem to "take" on that linked example...

...so sure enough, when I apply a different layout to that page, the check-boxes turn up nicely. So, there is potential for theme/layout conflict and this plugin's CSS. Worth knowing.

---

And nice work! big_smile

Last edited by David (2015-04-03 12:24)

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

3

Re: Survey Generator Plugin

Thank you, David, and thank you svenlaere, who wrote me a private message to advise me of the documentation error. I will fix that asap.

I also forgot to mention the included sample file, so thanks for digging deeper and not giving up.

Can you tell me what theme seemed to conflict with the plugin's CSS? Is it a standard theme I can download to examine?

svenlaere mentioned "I rather see the use of labels in the generated HTML for easy selection: http://www.w3.org/TR/WCAG20-TECHS/H44.html"

Yes, agreed 100%! I want to make the form accessible to screen readers. However, in the case where there's a panel of questions, all with the same answer choices, individual questions have no text associated with them. So instead, I used the title attribute. I had read that virtually all screen readers today will read the title attribute if it's attached to a radio or checkbox control. Does anyone know if that's not true?

Thank you both for your encouragement!

Thumbs up

4

Re: Survey Generator Plugin

RobertH wrote:

Can you tell me what theme seemed to conflict with the plugin's CSS? Is it a standard theme I can download to examine?

I cloned the page on the site, so you can see the difference the layout makes.

You can see the "Baseline" theme at jackie's Project 79 site (it's also in our wiki here, of course, but that part of the site is scheduled for reorganization). The table CSS is not getting used....

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

5

Re: Survey Generator Plugin

P.s. @RobertH - this could actually make a great little star-ranking system (like Amazon's, for example). Do you have anything like that pre-packaged?

Also, I haven't poked through your code yet - are there any "flood-prevention" measures in place?

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

6

Re: Survey Generator Plugin

David, it seems that Baseline theme does not have checkboxes or radio buttons. At least I don't see them.

Tutorials at Project 79 | Wolf CMS Docs

7

Re: Survey Generator Plugin

David wrote:

P.s. @RobertH - this could actually make a great little star-ranking system (like Amazon's, for example). Do you have anything like that pre-packaged?

Eh, I don't think so. I have the survey code as a separate stand-alone package. I suppose a star-ranking system would be a one-question survey but would also include an updated count.

David wrote:

Also, I haven't poked through your code yet - are there any "flood-prevention" measures in place?

Oh, yes, I thought about that. I first coded the survey because a professor whose website I maintain wanted to survey his students. I definitely wanted to prevent some prankster from filling out the survey once and then hitting back-button and submitting 100 duplicate surveys in short order. So here's what happens.

You get the form, and you fill it out and click submit. The system saves your survey data and then redisplays your filled-out survey form but all the controls are disabled and the form has no buttons. This allows you to print your filled out survey but does not allow you to resubmit the form.

Now suppose you refresh the page. Well, here's the code (I've removed code unnecessary to explain this).

function survey_conduct($survey_name = '') {
  if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $survey = new Survey;
    $save = $survey->get_variables();
    $_SESSION['save'] = $save;
  }
  else {
    if (!isset($_SESSION['save'])) {
      exit(__('Survey is finished'));
    }
    $survey = new Survey;
    $save = $_SESSION['save'];
    $survey->set_variables($save);
    $survey->update_survey_data($_POST['survey_data']);
    if ($survey->validate_errors() == 0) {
      $survey->save_data();
      unset($_SESSION['save']);
    }
  }
  $survey->render_form();
}

The first time through, the request method will be a GET, so the survey object is created and its data is saved to the session. When the user submits the survey, the request method will be POST, and if there's no data saved in the session, execution ends. If the data is found in the session, the survey data is updated and saved, and then the data is removed from the session. That way, if you do a POST a second time, execution will stop with the message "Survey is finished."

Now suppose you instead press the back button to return to your survey form just before you hit submit. In that case, Javascript will reset the form, and you'll get a blank form.

PS, I know it's not safe to use raw $_POST data, but this consists only of check box and radio button choices, so I didn't see what the security concern could be. I can clean that up if recommended.

By the way, I cannot access the site http://erajad.esy.es/ at all. My browser keeps saying the connection timed out. It's not a DNS problem. My nslookup finds the site's IP, but even trying to access the site by IP gives me a connection timed out error. Tracert gives up halfway through as well. I'm sure it's not your site but something at my end. American internet is about the worst in the developed world.

Last edited by RobertH (2015-04-06 01:32)

Thumbs up

8

Re: Survey Generator Plugin

Thanks to Samuel (svanlaere) and David's advice, I've moved this plugin forward quite a bit in the last few days.

* I've moved all HTML output to view files.
* I've replaced most title attributes with proper labels. (still work to do here)
* I've removed all CSS styling.
* I've cleaned up the documentation.
* I've changed all <?= to <?php echo. smile

I will continue polishing and improving it, of course.

The plugin is now on GitHub, at https://github.com/RobertHallsey/Survey … r-Wolf-CMS. Please feel free to submit any pull requests you wish, and thanks if you do.

Thumbs up

9

Re: Survey Generator Plugin

Ok, with help from good people, my survey plugin is finally ready for a real release.

In addition to going over the code with a magnifying glass, I've enhanced the documentation, provided a CSS file, added GPL3 blurbs to all files, and got custom icons.

My question now is how can I have it incorporated into the Wolf CMS repository?
If there are conditions or terms, I'm sure I can comply.

Also, I noticed that many of the plugins in the repository are very old. I volunteer to help clean up the repository. I don't actually need any kind of special access to the repository. I can check each plugin to see if it's compatible with 0.8.2, contact the plugin developer, and report back on the results.

Thumbs up +1

10

Re: Survey Generator Plugin

My question now is how can I have it incorporated into the Wolf CMS repository?
If there are conditions or terms, I'm sure I can comply.

In the upper right corner you have My Account | Logout. Go to your account and you'll see "Add a new plugin" in the sidebar. Follow on screen instructions.

Also, I noticed that many of the plugins in the repository are very old. I volunteer to help clean up the repository. I don't actually need any kind of special access to the repository. I can check each plugin to see if it's compatible with 0.8.2, contact the plugin developer, and report back on the results.

Yes you are right, and a lot of them are useless now probably.
Are you sure you want to do this?

IMO, it would be great but it's a lot of work.

Tutorials at Project 79 | Wolf CMS Docs

11

Re: Survey Generator Plugin

jackie wrote:
RobertH wrote:

Also, I noticed that many of the plugins in the repository are very old. I volunteer to help clean up the repository.....

Yes you are right, and a lot of them are useless now probably.
Are you sure you want to do this?

IMO, it would be great but it's a lot of work.

What jackie said. cool That would be great! There is probably some "low-hanging fruit" in there.

I notice the LibreOffice templates and extensions site includes an automated warning based on last update. I wonder if adding something like that is worth us thinking about, too? (For any future repo, that is.)

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

12

Re: Survey Generator Plugin

Thanks jackie.

Yeah, it sounds like a lot of work, but if I verify even two or three plugins a week, that should move things forward. And for what it's worth, I'm just talking about checking if they work under 0.8.2.

Thumbs up

13

Re: Survey Generator Plugin

RobertH wrote:

And for what it's worth, I'm just talking about checking if they work under 0.8.2.

I just used "First child" on a site - last tested with 0.7.5, but works great on 0.8.2.

So that's one done. smile I wonder if it's worth starting a thread for this purpose?

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

14

Re: Survey Generator Plugin

These work:

- Fancy image gallery (from master branch)
- Form 0.2
- CKEditor
- Truncate

Tutorials at Project 79 | Wolf CMS Docs