adding a block of matrix field from a front end entry form 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!
&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;
With the help of CreateSean comment I have managed to fix the problems in the form.
Here it is for future reference for everyone:
&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;