<p>I ran into this a while ago and it drove me nuts. Try adding <code>disabled</code> and <code>selected</code> attributes to your initial option in the select. So in your case <code>&lt;option disabled selected&gt;---&lt;/option&gt;</code>.</p>

CC BY-SA 3.0
2016-02-17T20:29:33.293Z
This is perfect, except... once you have selected a different option there is no going back to the `---` one. Probably need javascript for that, but my problem is solved.
Marion Newlevant
CC BY-SA 3.0
2016-02-17T19:51:24.903Z
2016-02-17T19:51:24.903Z
Chase Giunta
<p>How to use select dropdown with entries/saveEntry for an entry field?</p>

<p>I have an entry with a field that is another entry, which I want to update with a form:</p>

<pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
  {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
  &lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
  &lt;label&gt;Vendor
    &lt;select name="fields[vendor][]"&gt;
      &lt;option&gt;---&lt;/option&gt;
      {% for v in craft.entries.section('vendors') %}
        &lt;option value="{{v.id}}"&gt;{{v.title}}&lt;/option&gt;
      {% endfor %}
    &lt;/select&gt;
  &lt;/label&gt;
  &lt;input type="submit" value="Submit"/&gt;
&lt;/form&gt;
</code></pre>

<p>This works fine, except if nothing is selected in the dropdown (<code>&lt;option&gt;---&lt;/option&gt;</code>). In that case, the POST value for <code>fields[vendor][]</code> is <code>---</code>, and I get a SQL foreign key constraint error.</p>

<p>I have also tried <code>&lt;option value=""&gt;---&lt;/option&gt;</code> and <code>&lt;option value="NULL"&gt;---&lt;/option&gt;</code> with no better outcome.</p>

CC BY-SA 3.0
2016-02-17T19:16:44.477Z
Been a while since I've dealt with this, but I did come up with this same error. Try adding `selected="selected"` to the option. I think the issue is submitting a field with empty data. The form isn't submitted with that option selected.
Chase Giunta
CC BY-SA 3.0
2016-02-17T19:29:10.683Z
@ChaseGiunta - pretty sure the `selected=selected` only affects which choice is initially selected, and nothing in the post data. In any event, it didn't help (unfortunately)
Marion Newlevant
<frontend><saveentry>
How to use select dropdown with entries/saveEntry for an entry field?
# How to use select dropdown with entries/saveEntry for an entry field?

(Asked by: username_0 on 2016-02-17)

How to use select dropdown with entries/saveEntry for an entry field?
I have an entry with a field that is another entry, which I want to update with a form:

  {{ getCsrfInput() }}
  
  
  Vendor
    
      ---
      {% for v in craft.entries.section('vendors') %}
        {{v.title}}
      {% endfor %}
    
  
  


This works fine, except if nothing is selected in the dropdown (---). In that case, the POST value for fields[vendor][] is ---, and I get a SQL foreign key constraint error.
I have also tried --- and --- with no better outcome.

**Tags:** frontend, saveentry

> **Comments:**
> **username_1**: Been a while since I've dealt with this, but I did come up with this same error. Try adding `selected="selected"` to the option. I think the issue is submitting a field with empty data. The form isn't submitted with that option selected.  
> **username_0**: @ChaseGiunta - pretty sure the `selected=selected` only affects which choice is initially selected, and nothing in the post data. In any event, it didn't help (unfortunately)  

---

## 1 answers

### Answer by username_1 on 2016-02-17. Score: 3 | Accepted answer

I ran into this a while ago and it drove me nuts. Try adding `disabled` and `selected` attributes to your initial option in the select. So in your case `---`.

> **Comments:**
> **username_0**: This is perfect, except... once you have selected a different option there is no going back to the `---` one. Probably need javascript for that, but my problem is solved.  

---

