<p>You seem to be missing the block <code>type</code>:</p>
<pre><code>&lt;input type=&quot;hidden&quot; name=&quot;fields[planningSchedule][blocks][new:1][type]&quot; value=&quot;text&quot; /&gt;
</code></pre>
<p>and change the <code>value</code> to your block type (handle).</p>

CC BY-SA 4.0
2021-06-11T15:08:38.913Z
2021-06-11T15:08:38.913Z
Oli
<p>Thanks Oli! I got this working after making two changes:</p>
<ol>
<li>Add hidden field for declaring Matrix block type</li>
</ol>
<pre><code>{# For the new activity block #}
{{ hiddenInput('fields[planningSchedule][sortOrder][]', 'new:1') }}
{{ hiddenInput('fields[planningSchedule][blocks][new:1][type]', 'activity') }}
</code></pre>
<ol start="2">
<li>My Time field's select option values were not formatted correctly. Need to use <code>date('H:i')</code> format.</li>
</ol>
<pre><code>&lt;select id=&quot;{{ fieldTimeStart.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldTimeStart.handle }}][time]&quot; class=&quot;custom-select&quot; required=&quot;required&quot;&gt;
    &lt;option disabled selected hidden value=&quot;&quot;&gt;Select start time&lt;/option&gt;
    {% for i in 7..16 %}
        {% for increment in [':00',':15',':30',':45'] %}
            {% set value = i ~ increment %}
            &lt;option value=&quot;{{ value | date('H:i') }}&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}{{ increment }} {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
        {% endfor %}
    {% endfor %}
&lt;/select&gt;
</code></pre>

CC BY-SA 4.0
2021-06-11T15:53:22.047Z
2021-06-11T15:53:22.047Z
Roger Glenn
<p>I have an entry type with simple Matrix field which has just one block type [activity] and several other non-matrix fields.</p>
<p>My front-end entry form works perfectly on non-matrix fields, but for some reason I'm not able to insert new blocks into the matrix field.</p>
<p>Here's my form code that only deals with the matrix field:</p>
<pre><code>{# get field settings #}
{% set fieldTimeStart = craft.app.fields.getFieldById(253) %}
{% set fieldTimeEnd = craft.app.fields.getFieldById(249) %}
{% set fieldDescription = craft.app.fields.getFieldById(251) %}
{% set fieldLocation = craft.app.fields.getFieldById(250) %}
{% set fieldParticipants = craft.app.fields.getFieldById(252) %}

&lt;form method=&quot;post&quot; accept-charset=&quot;UTF-8&quot; enctype=&quot;multipart/form-data&quot;&gt;
{{ csrfInput() }}
{{ actionInput('entries/save-entry') }}
{{ hiddenInput('sectionId', '5') }}
{{ hiddenInput('enabled', '1') }}
{{ hiddenInput('entryId', entry.id) }}
{{ redirectInput(url('planning/schedule', {'diagnostic':diagnosticId})) }}

{# All existing blocks #}
{% for blockId in clone(entry.planningSchedule).anyStatus().ids() %}
    {{ hiddenInput('fields[planningSchedule][sortOrder][]', blockId) }}
{% endfor %}

{# For the new activity block #}
{{ hiddenInput('fields[planningSchedule][sortOrder][]', 'new:1') }}
{#
 # Including these hidden fields for the new matrix block results is &quot;entry not saved&quot; error
 #
{{ hiddenInput('fields[planningSchedule][blocks][new:1][type]', 'activity') }}
{{ hiddenInput('fields[planningSchedule][blocks][new:1][enabled]', '1') }}
#}

{# Prefix the block's input names with `fields[planningSchedule][blocks][new:1][fields]` #}
{% set fieldNamePrefix = 'fields[planningSchedule][blocks][new:1][fields]' %}

&lt;div class=&quot;form-row&quot;&gt;
    &lt;div class=&quot;form-group col-md-6&quot;&gt;
        &lt;label for=&quot;{{ fieldTimeStart.handle }}&quot;&gt;Start Time&lt;/label&gt;
        &lt;select id=&quot;{{ fieldTimeStart.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldTimeStart.handle }}][time]&quot; class=&quot;custom-select&quot; required=&quot;required&quot;&gt;
            &lt;option disabled selected hidden value=&quot;&quot;&gt;Select start time&lt;/option&gt;
            {% for i in 7..16 %}
            &lt;option value=&quot;{{ i }}:00&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:00 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:15&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:15 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:30&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:30 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:45&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:45 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            {% endfor %}
        &lt;/select&gt;
    &lt;/div&gt;
    
    &lt;div class=&quot;form-group col-md-6&quot;&gt;
        &lt;label for=&quot;{{ fieldTimeEnd.handle }}&quot;&gt;End Time&lt;/label&gt;
        &lt;select id=&quot;{{ fieldTimeEnd.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldTimeStart.handle }}][time]&quot; class=&quot;custom-select&quot; required&gt;
            &lt;option disabled selected hidden value=&quot;&quot;&gt;Select end time&lt;/option&gt;
            {% for i in 7..16 %}
            &lt;option value=&quot;{{ i }}:00&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:00 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:15&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:15 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:30&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:30 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            &lt;option value=&quot;{{ i }}:45&quot;&gt;{{ i &gt; 12 ? i - 12 : i }}:45 {{ i &lt; 12 ? 'am' : 'pm' }}&lt;/option&gt;
            {% endfor %}
        &lt;/select&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;form-group&quot;&gt;
    &lt;label for=&quot;{{ fieldDescription.handle }}&quot;&gt;Activity&lt;/label&gt;
    &lt;textarea class=&quot;form-control&quot; id=&quot;{{ fieldDescription.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldDescription.handle }}]&quot; placeholder=&quot;Describe activity&quot; required=&quot;required&quot;&gt;&lt;/textarea&gt;
&lt;/div&gt;

&lt;div class=&quot;form-row&quot;&gt;
    &lt;div class=&quot;form-group col-md-6&quot;&gt;
        &lt;label for=&quot;{{ fieldLocation.handle }}&quot;&gt;Location&lt;/label&gt;
        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;{{ fieldLocation.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldLocation.handle }}]&quot; placeholder=&quot;&quot; required&gt;
    &lt;/div&gt;
    
    &lt;div class=&quot;form-group col-md-6&quot;&gt;
        &lt;label for=&quot;{{ fieldParticipants.handle }}&quot;&gt;Participants&lt;/label&gt;
        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;{{ fieldParticipants.handle }}&quot; name=&quot;{{ fieldNamePrefix }}[{{ fieldParticipants.handle }}]&quot; placeholder=&quot;&quot; required&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;schedule-btn-container&quot;&gt;
    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Save Activity&lt;/button&gt;
&lt;/div&gt;

&lt;/form&gt;
</code></pre>
<p>And here's how the field inputs look on the rendered form:</p>
<pre><code>{# All existing blocks #}
&lt;input type=&quot;hidden&quot; name=&quot;fields[planningSchedule][sortOrder][]&quot; value=&quot;19132&quot;&gt;

{# For the new activity block #}
&lt;input type=&quot;hidden&quot; name=&quot;fields[planningSchedule][sortOrder][]&quot; value=&quot;new:1&quot;&gt;


&lt;select id=&quot;timeStart&quot; name=&quot;fields[planningSchedule][blocks][new:1][fields][timeStart][time]&quot; class=&quot;custom-select&quot; required=&quot;required&quot;&gt;
    &lt;option disabled=&quot;&quot; selected=&quot;&quot; hidden=&quot;&quot; value=&quot;&quot;&gt;Select start time&lt;/option&gt;
    &lt;option value=&quot;7:00&quot;&gt;7:00 am&lt;/option&gt;
    ...
&lt;/select&gt;

&lt;select id=&quot;timeEnd&quot; name=&quot;fields[planningSchedule][blocks][new:1][fields][timeStart][time]&quot; class=&quot;custom-select&quot; required=&quot;&quot;&gt;
    &lt;option disabled=&quot;&quot; selected=&quot;&quot; hidden=&quot;&quot; value=&quot;&quot;&gt;Select end time&lt;/option&gt;
    &lt;option value=&quot;7:00&quot;&gt;7:00 am&lt;/option&gt;
    ... 
&lt;/select&gt;

&lt;textarea class=&quot;form-control&quot; id=&quot;description&quot; name=&quot;fields[planningSchedule][blocks][new:1][fields][description]&quot; placeholder=&quot;Describe activity&quot; required=&quot;required&quot;&gt;&lt;/textarea&gt;

&lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;location&quot; name=&quot;fields[planningSchedule][blocks][new:1][fields][location]&quot; placeholder=&quot;&quot; required=&quot;&quot;&gt;

&lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;participants&quot; name=&quot;fields[planningSchedule][blocks][new:1][fields][participants]&quot; placeholder=&quot;&quot; required=&quot;&quot;&gt;
</code></pre>
<p>Comparing these field name attributes to what's used in the control panel, the only difference I can see is that the control panel uses [new1] instead of [new:1] for the temporary id of new blocks being inserted.</p>
<p>Neither [new1] nor [new:1] seem to make any difference.</p>
<pre><code>{# CONTROL PANEL INPUTS WHEN INSERTING NEW MATRIX BLOCK #}
{# Trimmed out extra attributes to focus on name attribute #}
&lt;input name=&quot;fields[planningSchedule][blocks][new1][fields][timeStart][time]&quot;&gt;
&lt;input name=&quot;fields[planningSchedule][blocks][new1][fields][timeEnd][time]&quot;&gt;
&lt;textarea name=&quot;fields[planningSchedule][blocks][new1][fields][description]&quot;&gt;&lt;/textarea&gt;
&lt;input name=&quot;fields[planningSchedule][blocks][new1][fields][location]&quot;&gt;
&lt;input name=&quot;fields[planningSchedule][blocks][new1][fields][participants]&quot;&gt;
</code></pre>
<p>After submitting the entry form with a new matrix block the flash message says &quot;Entry saved&quot; and any existing matrix blocks (created within the control panel) are retained, but the new matrix block is not saved to the entry.</p>
<p>I've also tried using the Guest Entries plugin to see if that makes any difference, but I get the same result either way... &quot;Entry saved&quot; but no new matrix block.</p>
<p>I've seen some posts here on stack exchange about this issue, but they seem to be very old and are probably for Craft 2 instead of Craft 3. Those posts seem to leave out [blocks] from the matrix field names, ex:</p>
<pre><code>&lt;input name=&quot;fields[planningSchedule][new:1][fields][location]&quot;&gt;

instead of

&lt;input name=&quot;fields[planningSchedule][blocks][new:1][fields][location]&quot;&gt;
</code></pre>
<p>I've tried both field name patterns and neither works.</p>
<p>If anyone can spot what I'm doing wrong I'd love to hear!</p>

<matrix><entry-form>
New Matrix blocks aren't saving via front-end entry form
# New Matrix blocks aren't saving via front-end entry form

(Asked by: username_0 on 2021-06-10)

I have an entry type with simple Matrix field which has just one block type [activity] and several other non-matrix fields.
My front-end entry form works perfectly on non-matrix fields, but for some reason I'm not able to insert new blocks into the matrix field.
Here's my form code that only deals with the matrix field:
{# get field settings #}
{% set fieldTimeStart = craft.app.fields.getFieldById(253) %}
{% set fieldTimeEnd = craft.app.fields.getFieldById(249) %}
{% set fieldDescription = craft.app.fields.getFieldById(251) %}
{% set fieldLocation = craft.app.fields.getFieldById(250) %}
{% set fieldParticipants = craft.app.fields.getFieldById(252) %}


{{ csrfInput() }}
{{ actionInput('entries/save-entry') }}
{{ hiddenInput('sectionId', '5') }}
{{ hiddenInput('enabled', '1') }}
{{ hiddenInput('entryId', entry.id) }}
{{ redirectInput(url('planning/schedule', {'diagnostic':diagnosticId})) }}

{# All existing blocks #}
{% for blockId in clone(entry.planningSchedule).anyStatus().ids() %}
    {{ hiddenInput('fields[planningSchedule][sortOrder][]', blockId) }}
{% endfor %}

{# For the new activity block #}
{{ hiddenInput('fields[planningSchedule][sortOrder][]', 'new:1') }}
{#
 # Including these hidden fields for the new matrix block results is "entry not saved" error
 #
{{ hiddenInput('fields[planningSchedule][blocks][new:1][type]', 'activity') }}
{{ hiddenInput('fields[planningSchedule][blocks][new:1][enabled]', '1') }}
#}

{# Prefix the block's input names with `fields[planningSchedule][blocks][new:1][fields]` #}
{% set fieldNamePrefix = 'fields[planningSchedule][blocks][new:1][fields]' %}


    
        Start Time
        
            Select start time
            {% for i in 7..16 %}
            {{ i > 12 ? i - 12 : i }}:00 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:15 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:30 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:45 {{ i < 12 ? 'am' : 'pm' }}
            {% endfor %}
        
    
    
    
        End Time
        
            Select end time
            {% for i in 7..16 %}
            {{ i > 12 ? i - 12 : i }}:00 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:15 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:30 {{ i < 12 ? 'am' : 'pm' }}
            {{ i > 12 ? i - 12 : i }}:45 {{ i < 12 ? 'am' : 'pm' }}
            {% endfor %}
        
    



    Activity
    



    
        Location
        
    
    
    
        Participants
        
    



    Save Activity




And here's how the field inputs look on the rendered form:
{# All existing blocks #}


{# For the new activity block #}




    Select start time
    7:00 am
    ...



    Select end time
    7:00 am
    ... 








Comparing these field name attributes to what's used in the control panel, the only difference I can see is that the control panel uses [new1] instead of [new:1] for the temporary id of new blocks being inserted.
Neither [new1] nor [new:1] seem to make any difference.
{# CONTROL PANEL INPUTS WHEN INSERTING NEW MATRIX BLOCK #}
{# Trimmed out extra attributes to focus on name attribute #}






After submitting the entry form with a new matrix block the flash message says "Entry saved" and any existing matrix blocks (created within the control panel) are retained, but the new matrix block is not saved to the entry.
I've also tried using the Guest Entries plugin to see if that makes any difference, but I get the same result either way... "Entry saved" but no new matrix block.
I've seen some posts here on stack exchange about this issue, but they seem to be very old and are probably for Craft 2 instead of Craft 3. Those posts seem to leave out [blocks] from the matrix field names, ex:


instead of



I've tried both field name patterns and neither works.
If anyone can spot what I'm doing wrong I'd love to hear!

**Tags:** matrix, entry-form

---

## 2 answers

### Answer by username_1 on 2021-06-11. Score: 1

You seem to be missing the block type:


and change the value to your block type (handle).


---

### Answer by username_0 on 2021-06-11. Score: 1

Thanks Oli! I got this working after making two changes:

Add hidden field for declaring Matrix block type

{# For the new activity block #}
{{ hiddenInput('fields[planningSchedule][sortOrder][]', 'new:1') }}
{{ hiddenInput('fields[planningSchedule][blocks][new:1][type]', 'activity') }}


My Time field's select option values were not formatted correctly. Need to use date('H:i') format.


    Select start time
    {% for i in 7..16 %}
        {% for increment in [':00',':15',':30',':45'] %}
            {% set value = i ~ increment %}
            {{ i > 12 ? i - 12 : i }}{{ increment }} {{ i < 12 ? 'am' : 'pm' }}
        {% endfor %}
    {% endfor %}


---

