Translations of this page:


void html(string text)

Outputs HTML code in the questionnaire. This means text can be output or images can be embedded. However, it is more sensible to use HTML for designing layouts (Placing Elements Side by Side).

  • text
    The HTML code which shall be displayed.


Note: It is usually better to create a Text in the List of Questions to store any longer HTML code. This text is than dragged into the questionnaire page like a question (Text Elements).

  <p>Line breaks
  will be ignored.</p>

HTML-Code and other elements

Other elements – especially questions and text elements – also generate HTML code. You can use html() to add more HTML code before and after these elements. This allows you, for example, to embed a question in another HTML element in order to change the width.

The following PHP code displays the question AB01 centered in a block with a maximum width of 600 pixels.

 html('<div style="max-width: 600px; margin: 0 auto;">');

You can find an application within the instructions for Placing Elements Side by Side.


Tip: It is better to use text elements to integrate text, images and lengthy HTML codes. These are created in Text Elements and Labels and dragged into the questionnaire or integrated into a questionnaire page with text(). As a result, the questionnaire remains clear, extended functions (e.g. multilingual surveys or placeholders) are available, and you do not have to worry about using quotation marks.

Note: The PHP functions echo and print() are not released for use in the questionnaire because their output would appear above the questionnaire, rather than in it. Use the function html() instead.

Note: In order to use quotation marks in text which already function as a delimiter, the quotation marks have to be devaluated with a back slash (\). After this, they will not be recognized as a delimiter anymore and displayed properly.

html('<p>This HTML code contains "double quotation marks".</p>');
html("<p>and so does &quot;this&quot;.</p>");
html('<p>This is how it works with single quotation marks</p>');
html('<h1>Hello world!</h1>');  // single quotation marks
html("<h1>Hello world!</h1>");  // double quotation marks 
html('<h1>Hello "world"</h1>');           // right
html("<h1>Hello &quot;world&quot;</h1>"); // even more right
html("<h1>Hello "world"</h1>"); // **Wrong**, because the string
                               // is tagged with double quotation marks and
                               // double quotation marks occur within.
// Spread the string out onto multiple lines - often sensible
// But usually text() is even more sensible 
  <h1>Hello world!</h1>
  <p>How are you, world?</p>

Note: Some words (e.g. “new”) must not appear in PHP code because they hold a particular meaning in PHP. If one of these words appears in your text, and you definitely want to use the command html() instead of a text element, then compile the text with fragments:

// Wrong: cannot be saved for security reasons
html('<p>This is a new car</p>');
// text() does not recognize this restriction
// And this workaround also works
html('<p>This is a ne'.'w car</p>');
en/create/functions/html.txt · Last modified: 09.03.2022 15:48 by admin
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki