<p>With the help of <a href="https://craftcms.stackexchange.com/users/193/createsean">CreateSean</a> comment I have managed to fix the problems in the form.</p>
<p>Here it is for future reference for everyone:</p>
<pre><code>&lt;form method=&quot;post&quot; accept-charset=&quot;UTF-8&quot; enctype=&quot;multipart/form-data&quot; class=&quot;edit-store&quot;&gt;
    {{ csrfInput() }}
    {{ actionInput('entries/save-entry') }}
    {{ redirectInput('members-zone/{slug}') }}
    {{ hiddenInput('movementCoursesEntries', '2') }}
    {{ hiddenInput('enabled', '1') }}
    &lt;input type=&quot;hidden&quot; name=&quot;entryId&quot; value=&quot;{{ entry.id }}&quot;&gt;

    {# various includes here #}
    &lt;input type=&quot;hidden&quot; name=&quot;fields[blocks]&quot; /&gt;

    {% for block in entry.videos %}
        {% if block.type == 'video_box' %}
            &lt;div class=&quot;matrixblock &quot;&gt;
                &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][{{ block.id }}][type]&quot; value=&quot;video_box&quot;&gt;
                &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][{{ block.id }}][enabled]&quot; value=&quot;1&quot;&gt;
                &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][{{ block.id }}][fields][videoTitle]&quot; value=&quot;{{ block.videoTitle }}&quot;&gt;
                &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][{{ block.id }}][fields][videoUrl]&quot; value=&quot;{{ block.videoUrl }}&quot;&gt;
            &lt;/div&gt;
        {% endif %}
    {% endfor %}
    {# hidden field with block type that is being updated #}
    &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][new_0][type]&quot; value=&quot;video_box&quot;&gt;
    {# is this block enabled #}
    &lt;input type=&quot;hidden&quot; name=&quot;fields[videos][new_0][enabled]&quot; value=&quot;1&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;fields[videos][new_0][fields][videoTitle]&quot; value=&quot;&quot; placeholder=&quot;Video Title&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;fields[videos][new_0][fields][videoUrl]&quot; value=&quot;&quot;  placeholder=&quot;Videl URL&quot;&gt;
    
    &lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-primary&quot;&gt;
&lt;/form&gt;
</code></pre>

CC BY-SA 4.0
2020-08-15T18:39:02.207Z
2020-08-15T18:39:02.207Z
LessMore Creative Studio
<p>I am trying to add a form to the frontend in which a registered user will be able to create and publish new block in a matrix field. I have read the documentation about it but am still failing miserably in achieving it...</p>
<p>The entry is part of a structure section with sectionId <code>movementCoursesEntries</code>. The matrix fieldId is <code>videos</code>. The blockId is <code>video_box</code> and it has two plain text fields <code>videoTitle</code> and <code>videoUrl</code>.</p>
<p>I have used this code but what I am getting is that the after submitting the form, all the old matrix blocks are being deleted and the new one is not being created. Any advice is highly appreciated!</p>
<pre><code>&lt;form method=&quot;post&quot; accept-charset=&quot;UTF-8&quot;&gt;
    {{ csrfInput() }}
    {{ actionInput('entries/save-entry') }}
    {{ redirectInput('/members-zone/{slug}') }}
    {{ hiddenInput('movementCoursesEntries', '2') }}
    {{ hiddenInput('enabled', '1') }}
    {{ hiddenInput('entryId', entry.id) }}
  
    {% if entry is defined %}
        {# Retain existing blocks + sort order #}
        {% for video_box in clone(entry.videos).anyStatus().ids() %}
            {{ hiddenInput('fields[videoTitle][sortOrder][]', video_box) }}
            {{ hiddenInput('fields[videoUrl][sortOrder][]', video_box) }}
        {% endfor %}
    {% endif %}

    {# Add a new text block #}
    {{ hiddenInput('fields[videoTitle][sortOrder][]', 'new:1') }}
    {{ hiddenInput('fields[videoUrl][sortOrder][]', 'new:1') }}

    {# Prefix the block's input names with `fields[&lt;FieldHandle&gt;][blocks][new:1]` #}
    {% namespace &quot;fields[blocks][blocks][new:1]&quot; %}
        {{ hiddenInput('type', 'text') }}
        &lt;input name=&quot;fields[videoTitle]&quot;&gt;
        &lt;input name=&quot;fields[videoUrl]&quot;&gt;
    {% endnamespace %}

  &lt;input type=&quot;submit&quot; value=&quot;Publish&quot;&gt;
&lt;/form&gt;
</code></pre>

CC BY-SA 4.0
2020-08-14T21:13:27.787Z
This blog post for craft 2 should help you get it working. You'll need to adapt for the changes from C2 to C3 https://caffeinecreations.ca/blog/editing-a-front-end-form-with-matrix/
CreateSean
<entries><matrix><frontend-form>
adding a block of matrix field from a front end entry form
# adding a block of matrix field from a front end entry form

(Asked by: username_0 on 2020-08-14)

I am trying to add a form to the frontend in which a registered user will be able to create and publish new block in a matrix field. I have read the documentation about it but am still failing miserably in achieving it...
The entry is part of a structure section with sectionId movementCoursesEntries. The matrix fieldId is videos. The blockId is video_box and it has two plain text fields videoTitle and videoUrl.
I have used this code but what I am getting is that the after submitting the form, all the old matrix blocks are being deleted and the new one is not being created. Any advice is highly appreciated!

    {{ csrfInput() }}
    {{ actionInput('entries/save-entry') }}
    {{ redirectInput('/members-zone/{slug}') }}
    {{ hiddenInput('movementCoursesEntries', '2') }}
    {{ hiddenInput('enabled', '1') }}
    {{ hiddenInput('entryId', entry.id) }}
  
    {% if entry is defined %}
        {# Retain existing blocks + sort order #}
        {% for video_box in clone(entry.videos).anyStatus().ids() %}
            {{ hiddenInput('fields[videoTitle][sortOrder][]', video_box) }}
            {{ hiddenInput('fields[videoUrl][sortOrder][]', video_box) }}
        {% endfor %}
    {% endif %}

    {# Add a new text block #}
    {{ hiddenInput('fields[videoTitle][sortOrder][]', 'new:1') }}
    {{ hiddenInput('fields[videoUrl][sortOrder][]', 'new:1') }}

    {# Prefix the block's input names with `fields[][blocks][new:1]` #}
    {% namespace "fields[blocks][blocks][new:1]" %}
        {{ hiddenInput('type', 'text') }}
        
        
    {% endnamespace %}

**Tags:** entries, matrix, frontend-form

> **Comments:**
> **username_1**: This blog post for craft 2 should help you get it working. You'll need to adapt for the changes from C2 to C3 https://caffeinecreations.ca/blog/editing-a-front-end-form-with-matrix/  

---

## 1 answers

### Answer by username_0 on 2020-08-15. Score: 2 | Accepted answer

With the help of username_1 comment I have managed to fix the problems in the form.
Here it is for future reference for everyone:

    {{ csrfInput() }}
    {{ actionInput('entries/save-entry') }}
    {{ redirectInput('members-zone/{slug}') }}
    {{ hiddenInput('movementCoursesEntries', '2') }}
    {{ hiddenInput('enabled', '1') }}
    

    {# various includes here #}
    

    {% for block in entry.videos %}
        {% if block.type == 'video_box' %}
            
                
                
                
                
            
        {% endif %}
    {% endfor %}
    {# hidden field with block type that is being updated #}
    
    {# is this block enabled #}


---

