Beispiel-Umfrage-Template

Beispiel-Umfrage-Template

Umfrage-Templates teilen sich in die HTML-Eingabe, CSS und Javascript auf.
HTML-Eingabe
CSS
Javascript
Editor-Ansicht
Vorschau
HTML-Eingabe
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <link rel="stylesheet" type="text/css" href="[CSS-HREF /] " />
  6.     <script src="[JS-SRC /]"></script>
  7.     <title>[SURVEY-HEADLINE /]</title>
  8. </head>
  9. <body>
  10.   <div class="container">
  11.     <img class="header-image" src="[SURVEY-IMAGE /]" />
  12.     <div class="pagination">Seite [PAGE-NB /] / [PAGE-COUNT /]</div>
  13.     <h1>[SURVEY-HEADLINE /]</h1>
  14.     [MESSAGE type='incomplete']
  15.     <div class="error">Bitte füllen Sie alle Pflichtfelder aus.</div>
  16.     [/MESSAGE][MESSAGE type='more']
  17.     <div class="error">Es wurden nicht genügend Antworten angehakt.</div>
  18.     [/MESSAGE][MESSAGE type='less']
  19.     <div class="error">Es wurden zu viele Antworten angehakt.</div>
  20.     [/MESSAGE]
  21.     <form action="[ACTION-URL /]" method="post">
  22.         [QUESTIONS]
  23.         [TOP]
  24.         <div class="questions">[/TOP]
  25.             [BETWEEN]
  26.             <div class="spacer"></div>
  27.             [/BETWEEN]
  28.             [BOTTOM]
  29.         </div>
  30.         [/BOTTOM]
  31.         [/QUESTIONS]

  32.         [ACTIONS]
  33.         [TOP]
  34.         <div class="actions">
  35.             <div class="mandatory-hint">* Pflichtfragen</div>
  36.             [/TOP]
  37.             [BETWEEN]<br />[/BETWEEN]
  38.             [BOTTOM]
  39.         </div>
  40.         [/BOTTOM] 

  41.         [ACTION type='back']
  42.         <input type="submit" name="btn_back" value="Zurück" class="back" />
  43.         [/ACTION]
  44.         [ACTION type='next']
  45.         <input type="submit" name="btn_submit" value="Weiter" class="more" />
  46.         [/ACTION]
  47.         [ACTION type='finish']
  48.         <input type="submit" name="btn_submit" value="Abschicken" class="finish" />
  49.         [/ACTION]
  50.         [/ACTIONS]

  51.     </form>
  52.     </div>
  53. </body>
  54. </html>
CSS
  1. @import url([SYSTEM key='redirect-domain' /]-google-api-css2/Roboto:wght@300;400;700);

  2. :root {
  3.   --primary: #3478F6;
  4. }

  5. * {
  6.   box-sizing: border-box; }

  7. body {
  8.   font-family: 'Roboto', Arial, sans-serif; font-size 1rem; line-height: auto; font-weight: 300; color: #333; margin: 0; padding: 0; background-color: #fefefe }

  9. img {
  10.   max-width: 100%; }

  11. .header-image {
  12.   width: 100%; }

  13. .container {
  14.   margin-left: auto;
  15.   margin-right: auto;
  16.   width: 1280px;
  17.   max-width: 100%;
  18.   padding: 15px; }

  19. form {
  20.   background-color: #f1f1f1;
  21.   padding: 30px;
  22.   border-radius: 2px;
  23. }

  24. .question .head {
  25.   padding-bottom: 10px; }

  26. .question .head label {
  27.   font-weight: 700; }

  28. .question .head label + div {
  29.   margin-top: 5px; }

  30. .question .body { }

  31. .spacer {
  32.   height: 20px; }

  33. input[type=text], textarea, select {
  34.   font-size: inherit;
  35.   font-family: inherit;
  36.   font-weight: inherit;
  37.   line-height: inherit;
  38.   width: 100%;
  39.   padding: 10px; }

  40. input[type=submit] {
  41.   font-size: inherit;
  42.   font-family: inherit;
  43.   line-height: inherit;
  44.   background-color: var(--primary);
  45.   color: #fff;
  46.   border: none; 
  47.   padding: 10px 20px;
  48.   font-weight: 400; }

  49.   /* rating */
  50.   .question.rating .body .rating_label.left {
  51.     padding-left: 0px;
  52.     padding-right: 0px; }

  53.   .question.rating .body .rating_label.right {
  54.     padding-left: 0px;
  55.     padding-right: 0px; }

  56.   .question.rating .body .rating_unit input[type="radio"] {
  57.       display: none; }

  58.   .question.rating .rating_unit {
  59.       font-size: 30px;
  60.       cursor: pointer;
  61.       color: #f2f2f2;
  62.       font-weight: 700;
  63.       text-shadow: 0px 0px 1px rgb(0, 0, 0); }

  64.   .question.rating .rating_unit:before {

  65.       content: '\2605'; }

  66.   .question.rating .rating_unit.active:before {
  67.       content: '\2605';
  68.       color: var(--primary);
  69.       font-weight: 700; }

  70.   .question.rating table {
  71.       width:auto;
  72.       margin-bottom:30px; }

  73.   .question.rating table td {
  74.     padding: 5px 15px; }
  75.   /* rating:end */

  76.   .error {
  77.     margin-top: 20px;
  78.     margin-bottom: 20px;
  79.     border: solid 1px #ff0000;
  80.     padding: 15px;
  81.     color: #ff0000;
  82.     background-color: rgba(255,0,0,.05);
  83.     font-weight: 400;
  84.     border-radius: 3px; }

  85.   .mandatory-hint {
  86.     margin-top: 20px;
  87.     margin-bottom: 20px; }

  88.   .pagination {
  89.     padding-top: 10px;
  90.     padding.bottom: 10px;
  91.   }
Javascript
Javascript für Bewertungs-Element
  1. var RatingQuestion = function(questionContainer) {
  2.   this.questionId = parseInt(questionContainer.id.split('_').pop(), 10);

  3.   this.ratingOptions = Array.from(
  4.     questionContainer.querySelectorAll('input[type="radio"]')
  5.   ).sort(function (a, b) {
  6.     return parseInt(a.value, 10) - parseInt(b.value, 10);
  7.   });
  8. };

  9. RatingQuestion.prototype.setActiveIndex = function(value) {
  10.   var optionsCount = this.ratingOptions.length;
  11.   var ratingValue = parseInt(this.ratingOptions[value].value, 10);

  12.   this.ratingOptions[value].checked = true;

  13.   for (var j = 0; j < optionsCount; ++j) {
  14.     var ratingParent = this.ratingOptions[j].parentElement;

  15.     if (!ratingParent) {
  16.       continue;
  17.     }

  18.     if (j < ratingValue) {
  19.       ratingParent.classList.add('active');
  20.     } else {
  21.       ratingParent.classList.remove('active');
  22.     }
  23.   }
  24. };

  25. RatingQuestion.prototype.init = function () {
  26.   this.ratingOptions.forEach(function (option, index) {
  27.     option.parentElement.addEventListener('click', function () {
  28.       this.setActiveIndex(index);
  29.     }.bind(this));
  30.   }.bind(this));

  31.   var currentValue = NaN;
  32.   var ratingRadioList = document.forms[0].elements['data[' + this.questionId + ']'];

  33.   if (ratingRadioList instanceof RadioNodeList) {
  34.     currentValue = parseInt(ratingRadioList.value, 10);
  35.   } else {
  36.     if (ratingRadioList.checked) {
  37.       currentValue = parseInt(ratingRadioList.value, 10);
  38.     }
  39.   }

  40.   if (!isNaN(currentValue)) {
  41.     this.setActiveIndex(currentValue - 1);
  42.   }
  43. };

  44. window.addEventListener('load', function () {
  45.   Array.from(document.querySelectorAll('.question.rating')).forEach(function (wrapper) {
  46.     var ratingQuestion = new RatingQuestion(wrapper);

  47.     window.setTimeout(function () {
  48.       ratingQuestion.init();
  49.     }.bind(this), 0);
  50.   });
  51. });
Editor-Ansicht
Die Ansicht im Editor ist unabhängig vom Quellcode des Umfrage-Templates da die verwendbaren Elemente (HTML-Element und Fragen) vorgegeben sind. Das Beispiel soll lediglich den Aufbau der Umfrage illustrieren.

Umfrage - Editor Ansicht, Tab Inhalte
Vorschau
Darstellung der Umfrage mit den unter "Editor-Ansicht" definierten Fragen.

Umfrage - Vorschau