Answers.Body: <p>You'll need to make sure the entries title is set otherwise that will throw an error. You can do this using a field in your form or set it in the Control Panel to automatically be set using another field.</p>
  
  <p>Currently you are setting the client field to save using an array with <code>[client][]</code> but the form input is set to <code>text</code> which only provides string values. </p>
  
  <p>This means that when you leave the field blank it uses an empty array as it's value ( <code>[""]</code> ) hence why you don't get the required validation error.</p>
  
  <p>If you want to provide an array of clients you'd need to use a different input type and also make sure that your client fieldType is set to something that can store arrays.</p>
  
  <p>Code suggestion:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
  
    &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
    &lt;input type="hidden" name="redirect" value="services/{slug}"&gt;
    &lt;input type="hidden" name="sectionId" value="3"&gt;
    &lt;input type="hidden" name="enabled" value="1"&gt;
  
    Title
    &lt;input type="text" name="title"&gt;&lt;br&gt;
  
    Service
    &lt;input type="text" name="fields[service]"&gt;&lt;br&gt;
  
    Client 
    &lt;input type="text" name="fields[client]"&gt;&lt;br&gt;
  
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  
  {% if entry is defined %}
    &lt;pre&gt;{{ dump(entry.getErrors()) }}&lt;/pre&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-15T19:00:41.160Z
Answers.Text: I must use the input field name `fields[client][]` because it's the only way (I know) to write in an entry field. `fields[client]` does nothing. The big question is how can I validate such a field?
Answers.UserDisplayName: Christian Steger
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-14T23:36:00.693Z
Answers.LastActivityDate: 2016-07-14T23:36:00.693Z
Answers.UserDisplayName: Luke Pearce
Body: <p>I have this simple code:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
  
      &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
      &lt;input type="hidden" name="redirect" value="services/{slug}"&gt;
      &lt;input type="hidden" name="sectionId" value="3"&gt;
      &lt;input type="hidden" name="enabled" value="1"&gt;
  
      Service &lt;input type="text" name="fields[service]"&gt;&lt;br&gt;
  
      {# Entry field (required) #}
      Client &lt;input type="text" name="fields[client][]"&gt;&lt;br&gt;
  
      &lt;input type="submit" value="Submit"&gt;
  
  &lt;/form&gt;
  
  {% if entry is defined %}
      &lt;pre&gt;{{ dump(entry.getErrors()) }}&lt;/pre&gt;
  {% endif %}
  </code></pre>
  
  <p>The client field is set as required.</p>
  
  <p>Submitting the form with empty client field I get no validation error but a CDbException.</p>
  
  <p>If I remove the line with the client input field I get a validation error as expected:</p>
  
  <blockquote>
    <p>array(1) {   ["client"]=>   array(1) {
        [0]=>
        string(23) "Client cannot be blank."   } }</p>
  </blockquote>
  
  <p>What am I missing?
  How can I validate entry fields?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-14T23:22:56.850Z
Comments.Text: What was the CDbException error?
Comments.UserDisplayName: Luke Pearce
Tags: <frontend><validation>
Title: Front-end entry field validation problem
ThreadText: # Front-end entry field validation problem
  
  (Asked by: username_0 on 2016-07-14)
  
  I have this simple code:
  
  ```
  <form method="post" accept-charset="UTF-8">
  
      <input type="hidden" name="action" value="entries/saveEntry">
      <input type="hidden" name="redirect" value="services/{slug}">
      <input type="hidden" name="sectionId" value="3">
      <input type="hidden" name="enabled" value="1">
  
      Service <input type="text" name="fields[service]"><br>
  
      {# Entry field (required) #}
      Client <input type="text" name="fields[client][]"><br>
  
      <input type="submit" value="Submit">
  
  </form>
  
  {% if entry is defined %}
      <pre>{{ dump(entry.getErrors()) }}</pre>
  {% endif %}
  
  ```
  
  The client field is set as required.
  
  Submitting the form with empty client field I get no validation error but a CDbException.
  
  If I remove the line with the client input field I get a validation error as expected:
  
  > array(1) { ["client"]=> array(1) {
  > [0]=>
  > string(23) "Client cannot be blank." } }
  
  What am I missing?
  How can I validate entry fields?
  
  **Tags:** frontend, validation
  
  > **Comments:**
  > **username_1**: What was the CDbException error?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-07-14. Score: 2
  
  You'll need to make sure the entries title is set otherwise that will throw an error. You can do this using a field in your form or set it in the Control Panel to automatically be set using another field.
  
  Currently you are setting the client field to save using an array with `[client][]` but the form input is set to `text` which only provides string values.
  
  This means that when you leave the field blank it uses an empty array as it's value ( `[""]` ) hence why you don't get the required validation error.
  
  If you want to provide an array of clients you'd need to use a different input type and also make sure that your client fieldType is set to something that can store arrays.
  
  Code suggestion:
  
  ```
  <form method="post" accept-charset="UTF-8">
  
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="redirect" value="services/{slug}">
    <input type="hidden" name="sectionId" value="3">
    <input type="hidden" name="enabled" value="1">
  
    Title
    <input type="text" name="title"><br>
  
    Service
    <input type="text" name="fields[service]"><br>
  
    Client 
    <input type="text" name="fields[client]"><br>
  
    <input type="submit" value="Submit">
  </form>
  
  {% if entry is defined %}
    <pre>{{ dump(entry.getErrors()) }}</pre>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: I must use the input field name `fields[client][]` because it's the only way (I know) to write in an entry field. `fields[client]` does nothing. The big question is how can I validate such a field?  
  
  ---
  
  