2

Im trying to use entry titles as options in a select field, similar to the last example on this page in the docs

My code looks like this:

<label>Position Applying For</label>
<select name="{{ positionApplyingFor.handle }}">
{% for entry in craft.entries.section('careers') %}
  <option value="{{ entry.title }}">
    {{ entry.title }}
  </option>
{% endfor %}
</select>

Although the form submits, the fields content is not shown in the admin.

If I add {% if field.value == entry.handle %} selected{% endif %}, I get the error "Variable "field" does not exist"

Any help appreciated!

Martin

3

The issue is you don't have a variable named input. I changed the code a little by included a variable named value. To make sure the proper option is selected you would need to pass back to the template a url param name with the currently selected option value. If there is a param and it has a value it will add that value to the variable value if not value will be blank.

<label>Position Applying For</label>
{% set value = craft.request.getParam("name")?? "" %}
<select name="{{ positionApplyingFor.handle }}">
    {% for entry in craft.entries.section('careers') %}
        <option value="{{ entry.title }}" {% if value == entry.title %}selected{% endif %}>
            {{ entry.title }}
        </option>
    {% endfor %}
</select>
  • 1
    Hi, thanks for your help. It seems that on submission the FreeForm ignores whatever Labels and Values are shown on the front end in favour of whatever is added to the Select field in the Composer - even if left blank. I tried adding tags but it just gives me tags back. Is it actually possible to have a dynamic Select menu? – Martin Jan 17 '17 at 9:28
  • This is possible. In the past I have setup a route then using javascript to call the route via ajax to retrieve the new options and append them to the select node element. – aran Jan 18 '17 at 14:49
  • 1
    If you're using a Select field type for the field, you would need to use a Text field type instead, as Select/Checkbox Group/Radio fields do not allow dynamic values at this time. This is something however, that we may add in the future though. :) – Solspace Jan 19 '17 at 16:36
  • No, i'm just trying to pull the Entry Title from the "careers" Section. This is working fine on the Front End but the values are not pulled through to the 'Submissions". – Martin Jan 19 '17 at 16:42
  • You mean when you view the submission in the CP, the value does not show for it? What type of field is it? – Solspace Jan 19 '17 at 16:53

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.