Welcome to the LimeSurvey Community Forum

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

Question theme answers are not saved

More
1 month 6 days ago #271137 by Neimlli_631203
LimeSurvey version: 6.15.4+250710
Installation type: Own server
Custom theme/template: Yes — custom question theme

Hi everyone,I'm trying to build a custom question theme to capture an address block in a structured way:
  • Row 1: Street and Suite/Apt fields side-by-side
  • Row 2: City, Province, and Postal Code (each in one column)
This layout isn't available by default in LimeSurvey, so I created a custom question theme based on the
Code:
Multiple Short Text
type.However, there's a critical issue: the answers are not being saved — nothing shows up in the response table, and no values are posted back.

What I noticed in the browser console:
  • All
    Code:
    <input>
    elements rendered without
    Code:
    id
    and
    Code:
    name
    attributes
  • Code:
    aSubQuestion
    returns
    Code:
    null
  • The HTML looks like this for each field: <input type="text" id="" name="" class="form-control" placeholder="Street" value="">
My config.xml
<config>
  <metadata>
    <name>addressblock</name>
    <type>question_theme</type>
    <title>Address Block</title>
    <creationDate>2025-07-23</creationDate>
    <lastUpdate>2025-07-23</lastUpdate>
    <author>Your Name</author>
    <authorUrl> your-site.example/
    <authorEmail>your@email.com
    <copyright>Copyright (C) 2025 Your Organization</copyright>
    <license>GNU General Public License version 2 or later</license>
    <version>1.0.0</version>
    <apiVersion>1</apiVersion>
    <lastSecurityUpdate>1.0.0</lastSecurityUpdate>
    <questionType>Q</questionType>
    <group>Text questions</group>
    <subquestions>5</subquestions>
    <answerscales>0</answerscales>
    <description>
      Collect an address with structured fields for street, suite, city, province, and postal code.
    </description>
  </metadata>

  <compatibility>
    <version>3.0</version>
    <version>4.0</version>
    <version>5.0</version>
    <version>6.0</version>
  </compatibility>

  <files>
    <css>
      <filename>css/addressblock.css</filename>
    </css>
    <js>
            <filename>js/addressblock.js</filename>
    </js>
  </files>

  <attributes>
    <attribute>
      <name>placeholder_street</name>
      <category>Display</category>
      <inputtype>text</inputtype>
      <default>Street Address</default>
      <caption>Street field placeholder</caption>
    </attribute>
    <attribute>
      <name>placeholder_suite</name>
      <category>Display</category>
      <inputtype>text</inputtype>
      <default>Apt/Suite</default>
      <caption>Suite field placeholder</caption>
    </attribute>
    <attribute>
      <name>placeholder_city</name>
      <category>Display</category>
      <inputtype>text</inputtype>
      <default>City</default>
      <caption>City field placeholder</caption>
    </attribute>
    <attribute>
      <name>placeholder_province</name>
      <category>Display</category>
      <inputtype>text</inputtype>
      <default>Province</default>
      <caption>Province field placeholder</caption>
    </attribute>
    <attribute>
      <name>placeholder_postal</name>
      <category>Display</category>
      <inputtype>text</inputtype>
      <default>Postal Code</default>
      <caption>Postal code field placeholder</caption>
    </attribute>
  </attributes>

  <engine>
    <load_core_css>true</load_core_css>
    <load_core_js>true</load_core_js>
    <show_as_template>true</show_as_template>
    <show_as_question_type>true</show_as_question_type>

</engine>
</config>



My answer.twig
{% block answer %}
<div class="address-block">
  <div class="row">
    {% for subquestion in subquestions %}
      {% if loop.index0 == 0 %}
        <div class="form-group col-md-8">
          <label for="{{ subquestion.sgqa }}">Street</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_street }}">
        </div>
      {% elseif loop.index0 == 1 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Suite</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_suite }}">
        </div>
      {% elseif loop.index0 == 2 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">City</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_city }}">
        </div>
      {% elseif loop.index0 == 3 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Province</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_province }}">
        </div>
      {% elseif loop.index0 == 4 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Postal Code</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_postal }}">
        </div>
      {% endif %}
    {% endfor %}
  </div>
</div>
{% endblock %}Question:Why are the input fields not being bound correctly to subquestions (no
Code:
name
,
Code:
id
, or values), and how can I fix this so that responses are captured?Any tips appreciated — especially if I missed something in the
Code:
config.xml
or
Code:
answer.twig
.Thanks in advance!

Please Log in to join the conversation.

More
1 month 6 days ago - 1 month 6 days ago #271138 by Joffm
Hi,
it would have been better you'd attached the entire question theme.
Then we can install it and see where there are mistakes.

BTW:
Why do you surround only one word with the "code" tags, like


but you do not when you insert real code, like the code of the "config.xml" or the "answer.twig"?
It would be better readable.
Code:
{% block answer %}
<div class="address-block">
  <div class="row">
    {% for subquestion in subquestions %}
      {% if loop.index0 == 0 %}
        <div class="form-group col-md-8">
          <label for="{{ subquestion.sgqa }}">Street</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_street }}">
        </div>
      {% elseif loop.index0 == 1 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Suite</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_suite }}">
        </div>
      {% elseif loop.index0 == 2 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">City</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_city }}">
        </div>
      {% elseif loop.index0 == 3 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Province</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_province }}">
        </div>
      {% elseif loop.index0 == 4 %}
        <div class="form-group col-md-4">
          <label for="{{ subquestion.sgqa }}">Postal Code</label>
          <input type="text" class="form-control" id="{{ subquestion.sgqa }}" name="{{ subquestion.sgqa }}" value="{{ subquestion.answer }}" placeholder="{{ question_template_attribute.placeholder_postal }}">
        </div>
      {% endif %}
    {% endfor %}
  </div>
</div>
{% endblock %}

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 6 days ago by Joffm.

Please Log in to join the conversation.

More
1 month 6 days ago #271139 by mohamed--chaaben
Thank you @Joffm for your feedback. You're actually right. Please find attached the question theme. I would appreciate any help.

Yours sincerely,

Please Log in to join the conversation.

More
1 month 6 days ago #271140 by mohamed--chaaben
Thank you @Joffm for your feedback, and sorry for the messy posting. Please find attached the zip file for the question theme. I would appreciate any help. I wanted to implement prefill (from the suvery using {TOKEN:ATTRIBUTE_X}) but I needed the answer fields to be identifiable.

Please Log in to join the conversation.

More
1 month 5 days ago - 1 month 1 day ago #271142 by tpartner
Without access to a computer I can see at least one problem. I don't think your variable {{ subquestion.sgqa }} is valid.

You need to use the variables available in the core question theme.

- github.com/LimeSurvey/LimeSurvey/blob/ma...r_row_inputtext.twig

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 month 1 day ago by tpartner.

Please Log in to join the conversation.

More
1 month 5 days ago - 1 month 5 days ago #271143 by tpartner
... for inspiration, here is a theme based on the multiple-short-text question type - github.com/tpartner/LimeSurvey-Image-Interest-Points-5x-6x

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 month 5 days ago by tpartner.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose