1

I've been able to repopulate text fields this way, but the radio buttons remain unchecked even when there was a value submitted.

{% for field in application.fieldMetaData %}
    {% set submittedValues = submittedValues|merge({ (field.handle): attribute(application, field.handle).value}) %}
{% endfor %}

{% if form|length %}
    {{ craft.freeform.form(form.handle, {
      returnUrl: '/',
      overrideValues: submittedValues
    }).render() }}
{% endif %}
  • I've discovered that this is not possible. You have to use manual form rendering to do this. – Mike Graham Feb 12 at 23:02
  • Glad you found a solution... would you mind adding it as an official answer in case it ends up helping someone in the future? – Brad Bell Feb 13 at 23:12
1

A little messy but here's how I got it to work in case anyone else has this question. It even seems to respect the conditional display rules on my form.

{% if form|length %}
    {{ form.renderTag }}

    {% if form.hasErrors %}
      <div class="freeform-form-has-errors">
        {{ "Error! Please review the form and try submitting again."|t('freeform') }}

        {% if form.errors|length %}
          <ul>
            {% for error in form.errors %}
              <li>{{ error }}</li>
            {% endfor %}
          </ul>
        {% endif %}
      </div>
    {% endif %}

    {% for row in form %}
      <div class="freeform-row {{ form.customAttributes.rowClass }}">
        {% for field in row %}
          {% set columnClass = "freeform-column " ~ form.customAttributes.columnClass %}
          {% if field.type == "submit" %}
            {% set columnClass = columnClass ~ " freeform-column-content-align-" ~ field.position %}
          {% endif %}
          {% if field.type == "radio_group" %}
            <div class="{{ columnClass }}"{{ field.rulesHtmlData }}>
                {{ field.renderLabel() }}
                <div class="freeform-instructions">
                 {{ field.renderInstructions() }}
                </div>
                {% if field.errors %}
                <ul class="errors freeform-errors">
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
                {% endif %}
                {% for option in field.options %}
                    <label>
                        <input type="radio" class="freeform-input" 
                          name="{{ field.handle }}" type="radio" 
                          id="form-input-{{ field.handle }}-{{ loop.index }}" 
                          value="{{ option.value }}" 
                          {{ option.value == submittedValues[field.handle] ? 'checked' : '' }}>
                        {{ option.label }}
                    </label>
                {% endfor %}
            </div>
          {% else %}
          <div class="{{ columnClass }}"{{ field.rulesHtmlData }}>
            {{ field.render({
              class: field.type != "submit" ? "freeform-input" : "",
              labelClass: "freeform-label" ~ (field.inputOnly ? " freeform-input-only-label" : "") ~ (field.required ? " freeform-required" : ""),
              errorClass: "freeform-errors",
              instructionsClass: "freeform-instructions",
              overrideValue: field.handle ? submittedValues[field.handle] : ''
            }) }}
          </div>
          {% endif %}
        {% endfor %}
      </div>
    {% endfor %}
    <input type="hidden" name="statusId" value="2">
    <input type="hidden" name="submissionId" value="{{ application.id }}">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">
    <input type="hidden" name="userEmail" value="{{ currentUser.email }}">
    {{ form.renderClosingTag }}
    {% endif %}

{% js %}
    var act = document.getElementsByName('action');
    act[0].value = 'freeform/submissions/save'
{% endjs %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.