<form method="post" action="{{ action }}">
  {% for group, fields in groups.items() %}
    <fieldset>
      <h5 class="mt-2">{{ group }}</h5>

      {% for field in fields %}
        <div class="mb-3">
          {% if field.input_type == "checkbox" %}
            <div class="form-check">
              <input id="{{field.name}}"
                     type="checkbox"
                     class="form-check-input"
                     name="{{ field.name }}"
                     {% if field.value %}checked{% endif %}
              >
              <label for="{{field.name}}" class="form-label">{{ field.meta.label }}</label>
            </div>
          {% elif field.input_type == "select" %}
            <label for="{{field.name}}" class="form-label">{{ field.meta.label }}</label>
            <select id="{{field.name}}"
                    class="form-select"
                    name="{{ field.name }}"
            >
              {% for option in field.options %}
              <option value="{{ option }}"
                {% if option == field.value %}selected{% endif %}
              >
                {{ option }}
              </option>
              {% endfor %}
            </select>
          {% else %}
            <label for="{{field.name}}" class="form-label">{{ field.meta.label }}</label>
            <input id="{{field.name}}"
                   type="{{field.input_type}}"
                   class="form-control"
                   name="{{ field.name }}"
                   value="{{ field.value or "" }}"
                   {% if field.meta.min != None %}min="{{ field.meta.min }}"{% endif %}
                   {% if field.meta.max != None %}max="{{ field.meta.max }}"{% endif %}
                   {% if field.meta.step != None %}step="{{ field.meta.step }}"{% endif %}
                   {% if field.meta.required %}required{% endif %}
            >
          {% endif %}

          {% if field.meta.help %}
          <div id="{{ field.name }}Help" class="form-text">{{ field.meta.help }}</div>
          {% endif %}
        </div>
      {% endfor %}
    </fieldset>
  {% endfor %}

  <button class="btn btn-primary">Save</button>
</form>
