<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>

CC BY-SA 3.0
2016-07-15T19:00:41.160Z
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?
Christian Steger
CC BY-SA 3.0
2016-07-14T23:36:00.693Z
2016-07-14T23:36:00.693Z
Luke Pearce
<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>

CC BY-SA 3.0
2016-07-14T23:22:56.850Z
What was the CDbException error?
Luke Pearce
<frontend><validation>
Front-end entry field validation problem
# Front-end entry field validation problem

(Asked by: username_0 on 2016-07-14)

I have this simple code:


    
    
    
    

    Service 

    {# Entry field (required) #}
    Client 

    



{% if entry is defined %}
    {{ dump(entry.getErrors()) }}
{% 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:


  
  
  
  

  Title
  

  Service
  

  Client 
  

  


{% if entry is defined %}
  {{ dump(entry.getErrors()) }}
{% 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?  

---

