Frontend form database error with empty Users field Within a frontend Add Product form (using Craft Commerce) I'm having problems with a database error whenever a Users field is left empty.

Here's the field:

{% set teachers = craft.users.group('teachers') %}
&lt;select name="fields[teacher][]"&gt;
&lt;option value=""&gt;n/a&lt;/option&gt;
{% for teacher in teachers %}
  &lt;option value="{{ teacher.id }}"&gt;{{ teacher.name }}&lt;/option&gt;
{% endfor %}
&lt;/select&gt;


I've tried setting the empty value to zero, but no luck. The forms works fine apart from this, so I don't think it's anything specific to Craft Commerce.
Figured it out. If you want to return an empty Users field, the field name attribute has to look like this:

&lt;select name="fields[teacher]" value=""&gt;


But if you want to return a non-empty Users field, the name attribute is different:

&lt;select name="fields[teacher][]" value="{user.id}"&gt;


So, I'm starting with the first example, and using an onChange event to switch the name attribute depending on whether the value is a valid user ID or not. Here's my final template code:

{% set teachers = craft.users.group('teachers') %}
&lt;select class="ui search dropdown" name="fields[teacher]" id="teacherselect"&gt;
&lt;option value="nA"&gt;n/a&lt;/option&gt;
{% for teacher in teachers %}
  &lt;option value="{{ teacher.id }}"&gt;{{ teacher.name }}&lt;/option&gt;
{% endfor %}
&lt;/select&gt;


And the jquery if anyone wants it:

($(this).val() == "nA") ? $(this).attr('name', 'fields[teacher]') : $(this).attr('name', 'fields[teacher][]')


This works.