Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-20T10:30:41.287Z
Answers.LastActivityDate: 2015-03-20T15:17:56.343Z
Answers.LastEditDate: 2015-03-20T15:17:56.343Z
Answers.UserDisplayName: Simon Clayson
Body: <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>
  
Tags: <form><guest-entries>
Title: Front-End Entry (Guest) saving correct values on error
ThreadText: # 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](http://buildwithcraft.com/docs/templating/entry-form)
  
  ```
  <input id="customField" type="text" name="fields[customField]"
  {%- if entry is defined %} value="{{ entry.customField }}"{% endif -%}>
  
  ```
  
  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:
  
  ```
  <select name="fields[honorific]">
      {% for honortitle in entry.honorific.options %}
          <option {%- if entry is defined %} value="{{ honortitle.value }}{% endif -%}">{% if entry is defined %}{{ honortitle.value }}</option>
      {% endfor %}
  </select>
  
  ```
  
  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, username_0
  
  **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!
  
  ```
   <select name="fields[honorific]">
       {% for honortitle in entry.honorific.options %}
           {% set chosen = false %}
  
           {% if honortitle.selected %}
               {% set chosen = true %}
           {% endif %}
  
           <option value="{{ honortitle.value }}"{% if chosen %} selected{% endif %}>{{ honortitle.label }}</option>
      {% endfor %}
   </select>
  
  ```
  
  
  ---
  
  