Answers.Body: <p>You could <code>dump</code> the <code>account</code> variable to see why the conditional doesn't work as you're expecting. I don't really see the reason to why you'd need the <code>in</code> containment test, but I'd just use <code>dump</code> for debugging.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-05T22:53:31.690Z
Answers.Text: `dump` was the answer. The system was saving the `label` as the actual field value. I've updated my question for anyone else. Not sure if it's a SmartMap thing? TBD...
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-05T19:51:08.380Z
Answers.LastActivityDate: 2016-03-05T19:51:08.380Z
Answers.UserDisplayName: carlcs
Body: <p>I am allowing guest registrations - everything is working fine. I am hung up on getting my drop down menu to repopulate/hold its value if there are any errors while submitting.</p>
  
  <p>I have a <code>states</code> field in the CP which is a dropdown.</p>
  
  <p>Within my twig template I have this:</p>
  
  <pre><code>{#
   # Get all of the states.
   #
   #}
   {% set states = craft.fields.getFieldByHandle('states').getFieldType.options %}
   {% if states|length %}
       &lt;div class="form-group"&gt;
           &lt;label for="state"&gt;State&lt;/label&gt;
           &lt;select id="state" name="fields[address][state]" class="form-control"&gt;
               &lt;option value=""&gt;Select&lt;/option&gt;
               {% for option in states %}
                   &lt;option val="{{ option.value }}"
                       {%- if account is defined and option.value in account.address.state %} selected {% endif -%}&gt;
                       {{ option.label }}
                   &lt;/option&gt;
               {% endfor %}
           &lt;/select&gt;
       &lt;/div&gt;
   {% endif %}
   {% if account is defined %}
       {{ errorList(account.getErrors('state')) }}
   {% endif %}
  </code></pre>
  
  <p>I am using SmartMap to capture my address hence the name of <code>fields[address][state]</code>. </p>
  
  <p>Just doing this:</p>
  
  <pre><code>{%- if account is defined %} selected {% endif -%}
  </code></pre>
  
  <p>Gets the last option selected, so I know <code>account</code> is getting defined, its something in my <code>and</code> part.</p>
  
  <p>All of my data is getting captured correctly, I just can't see past the obvious here I guess.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Thanks to @carlcs I found that the value of my <code>state</code> field was getting saved as the label. I'm not sure if thats a function of SmartMap, or something else I might have done.</p>
  
  <p>Here is what I ended up with:</p>
  
  <pre><code>...
  &lt;option value=""&gt;Select&lt;/option&gt;
  {% for option in states %}
      &lt;option val="{{ option.value }}"
          {%- if account is defined and option.label in account.address.state %} selected {% endif -%}&gt;
          {{ option.label }}
      &lt;/option&gt;
  {% endfor %}
  </code></pre>
  
  <p>Alternatively, here is how I was able to repopulate a "normal" drop-down (not address/SmartMap):</p>
  
  <pre><code>...
  &lt;option value=""&gt;Select&lt;/option&gt;
  {% for option in myField %}
      &lt;option val="{{ option.value }}"
      {%- if account is defined and option.label in account.myField.label %} selected {% endif -%}&gt;
         {{ option.label }}
      &lt;/option&gt;
  {% endfor %}
  </code></pre>
  
  <p>I think it's also worth noting that by setting <code>myField</code> as a required field in the CP, I needed to hard-code the <code>&lt;option value=""&gt;Select&lt;/option&gt;</code> in the template rather than putting it as a field value. When I had it as a field value, I (think) Craft was accepting that as a selected value and I was not getting the error message. </p>
  
Tags: <registration><validation>
Title: How can I repopulate my dropdown on a front-end form?
ThreadText: # How can I repopulate my dropdown on a front-end form?
  
  (Asked by: username_0 on 2016-03-05)
  
  I am allowing guest registrations - everything is working fine. I am hung up on getting my drop down menu to repopulate/hold its value if there are any errors while submitting.
  
  I have a `states` field in the CP which is a dropdown.
  
  Within my twig template I have this:
  
  ```
  {#
   # Get all of the states.
   #
   #}
   {% set states = craft.fields.getFieldByHandle('states').getFieldType.options %}
   {% if states|length %}
       <div class="form-group">
           <label for="state">State</label>
           <select id="state" name="fields[address][state]" class="form-control">
               <option value="">Select</option>
               {% for option in states %}
                   <option val="{{ option.value }}"
                       {%- if account is defined and option.value in account.address.state %} selected {% endif -%}>
                       {{ option.label }}
                   </option>
               {% endfor %}
           </select>
       </div>
   {% endif %}
   {% if account is defined %}
       {{ errorList(account.getErrors('state')) }}
   {% endif %}
  
  ```
  
  I am using SmartMap to capture my address hence the name of `fields[address][state]`.
  
  Just doing this:
  
  ```
  {%- if account is defined %} selected {% endif -%}
  
  ```
  
  Gets the last option selected, so I know `account` is getting defined, its something in my `and` part.
  
  All of my data is getting captured correctly, I just can't see past the obvious here I guess.
  
  **SOLUTION**
  
  Thanks to @username_1 I found that the value of my `state` field was getting saved as the label. I'm not sure if thats a function of SmartMap, or something else I might have done.
  
  Here is what I ended up with:
  
  ```
  ...
  <option value="">Select</option>
  {% for option in states %}
      <option val="{{ option.value }}"
          {%- if account is defined and option.label in account.address.state %} selected {% endif -%}>
          {{ option.label }}
      </option>
  {% endfor %}
  
  ```
  
  Alternatively, here is how I was able to repopulate a "normal" drop-down (not address/SmartMap):
  
  ```
  ...
  <option value="">Select</option>
  {% for option in myField %}
      <option val="{{ option.value }}"
      {%- if account is defined and option.label in account.myField.label %} selected {% endif -%}>
         {{ option.label }}
      </option>
  {% endfor %}
  
  ```
  
  I think it's also worth noting that by setting `myField` as a required field in the CP, I needed to hard-code the `<option value="">Select</option>` in the template rather than putting it as a field value. When I had it as a field value, I (think) Craft was accepting that as a selected value and I was not getting the error message.
  
  **Tags:** registration, validation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-05. Score: 2 | Accepted answer
  
  You could `dump` the `account` variable to see why the conditional doesn't work as you're expecting. I don't really see the reason to why you'd need the `in` containment test, but I'd just use `dump` for debugging.
  
  > **Comments:**
  > **username_0**: `dump` was the answer. The system was saving the `label` as the actual field value. I've updated my question for anyone else. Not sure if it's a SmartMap thing? TBD...  
  
  ---
  
  