Answers.Body: <p>I believe you're getting that error because you're supplying an array (<code>[]</code>) for the mother field and the only value in that array would be an empty string (<code>""</code>) if they select the <code>There is no mother</code> option. So what Craft is attempting to save as a relation is <code>[""]</code>. Instead of an array of integer ID numbers, it's getting an empty string which isn't a valid value.</p>
  
  <p>Even if you remove the value attribute of the option tag for the <code>There is no mother</code> option, the field will use the inner text of the tag as the value, so this does not solve your problem either.</p>
  
  <p>One suggestion would be to use radio buttons instead and do the following:</p>
  
  <pre><code>&lt;label&gt;&lt;input type="radio" name="" value=""&gt; There is no mother&lt;/label&gt;
  {% for mother in mothers %}
      &lt;label&gt;&lt;input type="radio" name="fields[mother][]" value="{{ mother.id }}"&gt; {{ mother.name }}&lt;/label&gt;
  {% endfor %}
  {% for user in users %}
      &lt;label&gt;&lt;input type="radio" name="fields[mother][]" value="{{ user.id }}"&gt; {{ user.name }}&lt;/label&gt;
  {% endfor %}
  </code></pre>
  
  <p>This will keep the field empty if someone selects the <code>There is no mother</code> option.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-10T18:21:33.317Z
Answers.Text: Hello Stephen, thanks for your answer. I'm affraid that radiobutton won't work in our case, because we have 600 users to choose from that could be a mother.
  
  But l want to ask it a little different. Let's say user 300 is my mother. What input value should I send to remove user 300 as my mother. 
  
  (So forget about select field)
Answers.UserDisplayName: John Stevens
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-10T19:17:01.147Z
Answers.Text: Ok figured it out. I can only send value="" to "fields[mother]" and not  to fields[mother][] because then it should be an array as you point out.
  
  I will use jQuery to solve this.
Answers.UserDisplayName: John Stevens
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T09:09:52.580Z
Answers.Text: Glad I could help @JohnStevens but looks like you got there on your own in the end :-)
Answers.UserDisplayName: Stephen Hamilton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T10:56:04.227Z
Answers.Text: Coming from EE, so there is still a lot to learn for me :)
Answers.UserDisplayName: John Stevens
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-10T16:14:04.740Z
Answers.LastActivityDate: 2016-10-10T16:43:02.440Z
Answers.LastEditDate: 2016-10-10T16:43:02.440Z
Answers.UserDisplayName: Stephen Hamilton
Body: <p>We have a change profile page where members can choose out of the users table who of the other members is their mother (or father).</p>
  
  <p>Below my (simplified) user profile form</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
  &lt;script&gt;$(':checkbox').checkboxpicker();&lt;/script&gt;
  {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="users/saveUser"&gt;
  &lt;input type="hidden" name="redirect" value="leden/wijzig-profiel?m=updated"&gt;
  &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  &lt;input type="hidden" name="fields[mother][]" value=""&gt;
  
  &lt;label for="mother"&gt;{{ 'mother'|t }}&lt;/label&gt;
  &lt;select name="fields[mother][]" &gt;
      &lt;option value=""&gt;There is no mother&lt;/option&gt;
      {% for mother in mothers %}
      &lt;option value="{{ mother.id }}"&gt;{{ mother.name }}&lt;/option&gt;
      {% endfor %}
      {% for user in users %}
      &lt;option value="{{ user.id }}"&gt;{{ user.name}}&lt;/option&gt;
      {% endfor %}    
  &lt;/select&gt;
  &lt;input type="submit" value="{{ 'Save'|t }}" name="proceed" &gt;
  </code></pre>
  
  <p></p>
  
  <p>I've tried to empty the field mother but that results in a CDbException error.</p>
  
  <pre><code>CDbCommand faalde tijdens het uitvoeren van volgend SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`familywebsite`.`craft_relations`, CONSTRAINT `craft_relations_targetId_fk` FOREIGN KEY (`targetId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, :row0_col3, :row0_col4, :row0_col5, :row0_col6, :row0_col7), (:row1_col0, :row1_col1, NULL, :row1_col3, :row1_col4, :row1_col5, :row1_col6, :row1_col7). Bound with :row0_col0='136', :row0_col1='1', :row0_col3='', :row0_col4=1, :row0_col5='2016-10-08 09:54:35', :row0_col6='2016-10-08 09:54:35', :row0_col7='e4211e99-5bbd-46c1-b703-c44e82bc4667', :row1_col0='136', :row1_col1='1', :row1_col3='2409', :row1_col4=2, :row1_col5='2016-10-08 09:54:35', :row1_col6='2016-10-08 09:54:35', :row1_col7='c0fb9927-89f1-4993-ba26-bc47a63bdc50'
  </code></pre>
  
  <p>This I can understand because the mother is a relation of the user, and by clearing the mother field value, it probably does not delete the relation and it will give and error like it does.</p>
  
  <p>So question is how to delete the relation with mother field?</p>
  
Tags: <users><relations><user-profile>
Title: Delete a relation in frontend form
ThreadText: # Delete a relation in frontend form
  
  (Asked by: username_0 on 2016-10-08)
  
  We have a change profile page where members can choose out of the users table who of the other members is their mother (or father).
  
  Below my (simplified) user profile form
  
  ```
  <form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
  <script>$(':checkbox').checkboxpicker();</script>
  {{ getCsrfInput() }}
  <input type="hidden" name="action" value="users/saveUser">
  <input type="hidden" name="redirect" value="leden/wijzig-profiel?m=updated">
  <input type="hidden" name="userId" value="{{ currentUser.id }}">
  <input type="hidden" name="fields[mother][]" value="">
  
  <label for="mother">{{ 'mother'|t }}</label>
  <select name="fields[mother][]" >
      <option value="">There is no mother</option>
      {% for mother in mothers %}
      <option value="{{ mother.id }}">{{ mother.name }}</option>
      {% endfor %}
      {% for user in users %}
      <option value="{{ user.id }}">{{ user.name}}</option>
      {% endfor %}    
  </select>
  <input type="submit" value="{{ 'Save'|t }}" name="proceed" >
  
  ```
  
  I've tried to empty the field mother but that results in a CDbException error.
  
  ```
  CDbCommand faalde tijdens het uitvoeren van volgend SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`familywebsite`.`craft_relations`, CONSTRAINT `craft_relations_targetId_fk` FOREIGN KEY (`targetId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, :row0_col3, :row0_col4, :row0_col5, :row0_col6, :row0_col7), (:row1_col0, :row1_col1, NULL, :row1_col3, :row1_col4, :row1_col5, :row1_col6, :row1_col7). Bound with :row0_col0='136', :row0_col1='1', :row0_col3='', :row0_col4=1, :row0_col5='2016-10-08 09:54:35', :row0_col6='2016-10-08 09:54:35', :row0_col7='e4211e99-5bbd-46c1-b703-c44e82bc4667', :row1_col0='136', :row1_col1='1', :row1_col3='2409', :row1_col4=2, :row1_col5='2016-10-08 09:54:35', :row1_col6='2016-10-08 09:54:35', :row1_col7='c0fb9927-89f1-4993-ba26-bc47a63bdc50'
  
  ```
  
  This I can understand because the mother is a relation of the user, and by clearing the mother field value, it probably does not delete the relation and it will give and error like it does.
  
  So question is how to delete the relation with mother field?
  
  **Tags:** users, relations, user-profile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-10. Score: 4 | Accepted answer
  
  I believe you're getting that error because you're supplying an array (`[]`) for the mother field and the only value in that array would be an empty string (`""`) if they select the `There is no mother` option. So what Craft is attempting to save as a relation is `[""]`. Instead of an array of integer ID numbers, it's getting an empty string which isn't a valid value.
  
  Even if you remove the value attribute of the option tag for the `There is no mother` option, the field will use the inner text of the tag as the value, so this does not solve your problem either.
  
  One suggestion would be to use radio buttons instead and do the following:
  
  ```
  <label><input type="radio" name="" value=""> There is no mother</label>
  {% for mother in mothers %}
      <label><input type="radio" name="fields[mother][]" value="{{ mother.id }}"> {{ mother.name }}</label>
  {% endfor %}
  {% for user in users %}
      <label><input type="radio" name="fields[mother][]" value="{{ user.id }}"> {{ user.name }}</label>
  {% endfor %}
  
  ```
  
  This will keep the field empty if someone selects the `There is no mother` option.
  
  > **Comments:**
  > **username_0**: Hello username_1, thanks for your answer. I'm affraid that radiobutton won't work in our case, because we have 600 users to choose from that could be a mother.  But l want to ask it a little different. Let's say user 300 is my mother. What input value should I send to remove user 300 as my mother.   (So forget about select field)  
  > **username_0**: Ok figured it out. I can only send value="" to "fields[mother]" and not  to fields[mother][] because then it should be an array as you point out.  I will use jQuery to solve this.  
  > **username_1**: Glad I could help @username_0 but looks like you got there on your own in the end :-)  
  > **username_0**: Coming from EE, so there is still a lot to learn for me :)  
  
  ---
  
  