<p>Digging into a past solution for checkboxes thanks to @bradbell, here's the answer!</p>

<pre><code> &lt;select name="fields[honorific]"&gt;
     {% for honortitle in entry.honorific.options %}
         {% set chosen = false %}

         {% if honortitle.selected %}
             {% set chosen = true %}
         {% endif %}

         &lt;option value="{{ honortitle.value }}"{% if chosen %} selected{% endif %}&gt;{{ honortitle.label }}&lt;/option&gt;
    {% endfor %}
 &lt;/select&gt;
</code></pre>

CC BY-SA 3.0
2015-03-20T10:30:41.287Z
2015-03-20T15:17:56.343Z
2015-03-20T15:17:56.343Z
Simon Clayson
<p>I'm building a Guest Entry Form, and one of the fields is a dropdown. Everything feeds through fine, but if one of the other fields has a validation error, I can save any inputted data with the code as outlined in the <a href="http://buildwithcraft.com/docs/templating/entry-form" rel="nofollow">Entry Form</a> </p>

<pre><code>&lt;input id="customField" type="text" name="fields[customField]"
{%- if entry is defined %} value="{{ entry.customField }}"{% endif -%}&gt;
</code></pre>

<p>But, with the dropdown, I can't get the value to stick, it always defaults to the first option (It's to grab a name title - eg, Mr. Mrs, Miss etc) on an error:</p>

<pre><code>&lt;select name="fields[honorific]"&gt;
    {% for honortitle in entry.honorific.options %}
        &lt;option {%- if entry is defined %} value="{{ honortitle.value }}{% endif -%}"&gt;{% if entry is defined %}{{ honortitle.value }}&lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
</code></pre>

<p>So, if I've already selected the option at the bottom of the list, how do I get the field to remember what I've selected if there's an error elsewhere?</p>

<p>Thanks, Simon</p>

<form><guest-entries>
Front-End Entry (Guest) saving correct values on error
# Front-End Entry (Guest) saving correct values on error

(Asked by: username_0 on 2015-03-16)

I'm building a Guest Entry Form, and one of the fields is a dropdown. Everything feeds through fine, but if one of the other fields has a validation error, I can save any inputted data with the code as outlined in the Entry Form 


But, with the dropdown, I can't get the value to stick, it always defaults to the first option (It's to grab a name title - eg, Mr. Mrs, Miss etc) on an error:

    {% for honortitle in entry.honorific.options %}
        {% if entry is defined %}{{ honortitle.value }}
    {% endfor %}


So, if I've already selected the option at the bottom of the list, how do I get the field to remember what I've selected if there's an error elsewhere?
Thanks, Simon

**Tags:** form, guest-entries

---

## 1 answers

### Answer by username_0 on 2015-03-20. Score: 1 | Accepted answer

Digging into a past solution for checkboxes thanks to @bradbell, here's the answer!
 
     {% for honortitle in entry.honorific.options %}
         {% set chosen = false %}

         {% if honortitle.selected %}
             {% set chosen = true %}
         {% endif %}

         {{ honortitle.label }}
    {% endfor %}


---

