I'm working on a site that was partially built by another dev and am having some trouble with Sprout Forms.
It's partially working but when I add a new field (sailSeries) to the template (it exists in the sprout forms control panel) I get this error:
Craft\SproutForms_EntryModel and its behaviors do not have a method or closure named "sailSeries".
Expanding on what the original dev has I added the sails series inside this for loop at the bottom.
{% for tab in form.getFieldLayout().getTabs() %}
{% set fields = tab.getFields() %}
{% for field in fields %}
{% set required = field.required %}
{% set tabId = field.tabId %}
{% set field = field.getField() %}
{% if field.handle == 'contactType' %}
{% set dropdownField = field %}
{% endif %}
various more fields
{% if field.handle == 'sailSeries' %}
{% set sailSeries = field %}
{% endif %}
{% endfor %}
{% endfor %}
The the code later in the template to have the field display:
<div class="frm-row">
<div class="section colm colm6">
{% set submittedDropdownValue = attribute(submittedEntry, sailSeries.handle) %}
<label class="field select">
{{ sailSeries.name }}
<select id="sailSeries" name="sailSeries">
{% for option in sailSeries.settings.options %}
{% set defaultValue = option.default ? option.value : null %}
{% set selectedDropdownValue = submittedDropdownValue != '' ? submittedDropdownValue : defaultValue %}
<option value="{{ option.value }}" {% if selectedDropdownValue == option.value %}selected="selected"{% endif %}>{{ option.label }}</option>
{% endfor %}
</select>
<i class="arrow"></i>
</label>
</div><!-- end section -->
</div><!-- /.frm-row -->
As soon as I add this in I get errors. Not sure why or how to troubleshoot. Please advise.
Revised code and now I'm getting this error:
Variable "sailSeries" does not exist.
no clue why this is happening.
sailSeries
variable is defined on the initial page load before form submission.SproutForms_EntryModel
is going to be null until after you submit a form. Once a form is submitted, a Form Entry is created and the form values are returned to the page as aSproutForms_EntryModel
. On the first page load (before a form is submitted), you'll need to check and confirm that theSproutForms_EntryModel
exists before you try to access any attributes that it contains.