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:
<form method="post" accept-charset="UTF-8">
{{ getCsrfInput() }}
<input type="hidden" name="action" value="entries/saveEntry">
<input type="hidden" name="entryId" value="{{ entry.id }}">
<label>Vendor
<select name="fields[vendor][]">
<option>---</option>
{% for v in craft.entries.section('vendors') %}
<option value="{{v.id}}">{{v.title}}</option>
{% endfor %}
</select>
</label>
<input type="submit" value="Submit"/>
</form>
This works fine, except if nothing is selected in the dropdown (<option>---</option>
). In that case, the POST value for fields[vendor][]
is ---
, and I get a SQL foreign key constraint error.
I have also tried <option value="">---</option>
and <option value="NULL">---</option>
with no better outcome.
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.selected=selected
only affects which choice is initially selected, and nothing in the post data. In any event, it didn't help (unfortunately)