<p><a href="https://craftcms.com/docs/4.x/matrix-fields.html#saving-matrix-fields" rel="nofollow noreferrer">As per the documentation</a>, you need to include the <code>sortOrder</code> parameter to save multiple blocks. Include three hidden fields to pass the three new block IDs (<code>new1</code>, <code>new2</code>, <code>new3</code>) as a <code>sortOrder</code> array and the field should save successfully.</p>
<pre class="lang-twig prettyprint-override"><code>&lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][sortOrder][]&quot; value=&quot;new1&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][sortOrder][]&quot; value=&quot;new2&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][sortOrder][]&quot; value=&quot;new3&quot;&gt;
</code></pre>
<p>By the way, this line is not doing anything and <em>might</em> mess something up:</p>
<pre class="lang-twig prettyprint-override"><code>&lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement]&quot;/&gt;
</code></pre>

CC BY-SA 4.0
2022-08-02T07:17:31.753Z
Hi, thanks for your answer. I have added the code which is not showing any fields when a user completest the form.
aren
CC BY-SA 4.0
2022-08-02T07:23:54.960Z
@aren Make sure to check the `network` tab in your devtools to see if the request contains the correct payload and what response you're getting. Also, have you checked if the users in question have the required permission to update this entry? Check the logs as well to see if you're getting any errors.
MoritzLost
CC BY-SA 4.0
2022-08-02T07:52:40.903Z
I'm not getting any errors, I have assigned all the rights to the user to test but in the logs I don't find the field either.
aren
CC BY-SA 4.0
2022-08-02T08:16:50.777Z
Okay I got it somehow working by adding this line (<input type="hidden" name="fields[deviceManagement]"/>) only one
aren
CC BY-SA 4.0
2022-07-20T13:27:23.457Z
2022-07-20T13:27:23.457Z
MoritzLost
<p>I am using a matrix field for registered users on my site.
I want to be able to add a certain amount of matrix blocks to each users on registration (with hidden input), so I can re-use them later on.</p>
<p>For now this kinda works, when a user registers only one block is added.</p>
<p>My question: How can I add the other matrix blocks to the user.</p>
<p>Used this code below (which is inside the form)(hidden-devices.twig):</p>
<pre><code>&lt;div class=&quot;matrixblock&quot; data-id=&quot;new1&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement]&quot;/&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new1][type]&quot; value=&quot;device&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new1][enabled]&quot; value=&quot;1&quot;&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new1][fields][macadres]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new1][fields][serial]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new1][fields][webkey]&quot; value=&quot;&quot;&gt;
    &lt;/div&gt;
    &lt;div class=&quot;matrixblock&quot; data-id=&quot;new2&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement]&quot;/&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new2][type]&quot; value=&quot;device&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new2][enabled]&quot; value=&quot;1&quot;&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new2][fields][macadres]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new2][fields][serial]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new2][fields][webkey]&quot; value=&quot;&quot;&gt;
    &lt;/div&gt;
    &lt;div class=&quot;matrixblock&quot; data-id=&quot;new3&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement]&quot;/&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new3][type]&quot; value=&quot;device&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new3][enabled]&quot; value=&quot;1&quot;&gt;

          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new3][fields][macadres]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new3][fields][serial]&quot; value=&quot;&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;fields[deviceManagement][new3][fields][webkey]&quot; value=&quot;&quot;&gt;
    &lt;/div&gt;
</code></pre>
<p>the form(register.twig):</p>
<pre><code>&lt;form class=&quot;c-forms&quot; method=&quot;post&quot; accept-charset=&quot;UTF-8&quot; id=&quot;19898981&quot;&gt;
        {% set page = craft.entries.section('login').one() %}
        {{ csrfInput() }}
        {{ actionInput('users/save-user') }}
        {{ redirectInput(page.url) }}
        {% include &quot;_components/hidden-devices.twig&quot; %}

        &lt;div class=&quot;container&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
          
            &lt;div class=&quot;col-lg-4 col-md-6 col-sm-12 col-xs-12 col-xl-4 col-xxl-4&quot;&gt;
              &lt;label class=&quot;c-forms__label&quot; for=&quot;firstName&quot;&gt;{{ entry.registerVoornaamLabel }}&lt;/label&gt;
              &lt;input class=&quot;c-forms__input&quot; class=&quot;form-control&quot; type=&quot;text&quot; id=&quot;firstName&quot; name=&quot;firstName&quot; placeholder=&quot;{{ entry.registerVoornaamPlaceholder }}&quot; autocomplete=&quot;given-name&quot; required&gt;
              {{ user ? _self.errorList(user.getErrors('firstName')) }}

              &lt;label class=&quot;c-forms__label&quot; for=&quot;bedrijf&quot;&gt;{{ entry.registerCompanyLabel }}&lt;/label&gt;
              &lt;input class=&quot;c-forms__input&quot; type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;bedrijf&quot; name=&quot;fields[bedrijf]&quot; placeholder=&quot;{{ entry.registerCompanyPlaceholder }}&quot; required&gt;
              {{ user ? _self.errorList(user.getErrors('fields[bedrijf]')) }}

              &lt;label class=&quot;c-forms__label&quot; for=&quot;btw&quot;&gt;{{ entry.registerBtwLabel }}&lt;/label&gt;
              &lt;input class=&quot;c-forms__input&quot; type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;btw&quot; name=&quot;fields[btw]&quot; placeholder=&quot;{{ entry.registerBtwPlaceholder }}&quot; required&gt;
              {{ user ? _self.errorList(user.getErrors('fields[btw]')) }}

              

            &lt;/div&gt;
       &lt;/div&gt;
    &lt;/div&gt;
&lt;/form&gt;

</code></pre>

<matrix><form><field><blocks>
Adding multiple blocks for matrix in form
# Adding multiple blocks for matrix in form

(Asked by: username_0 on 2022-07-20)

I am using a matrix field for registered users on my site.
I want to be able to add a certain amount of matrix blocks to each users on registration (with hidden input), so I can re-use them later on.
For now this kinda works, when a user registers only one block is added.
My question: How can I add the other matrix blocks to the user.
Used this code below (which is inside the form)(hidden-devices.twig):

          

          
          

          
          
          
    
    
          

          
          

          
          
          
    
    
          

          
          

          
          
          
    

the form(register.twig):

        {% set page = craft.entries.section('login').one() %}
        {{ csrfInput() }}
        {{ actionInput('users/save-user') }}
        {{ redirectInput(page.url) }}
        {% include "_components/hidden-devices.twig" %}

        
          
          
            
              {{ entry.registerVoornaamLabel }}
              
              {{ user ? _self.errorList(user.getErrors('firstName')) }}

              {{ entry.registerCompanyLabel }}
              
              {{ user ? _self.errorList(user.getErrors('fields[bedrijf]')) }}

              {{ entry.registerBtwLabel }}
              
              {{ user ? _self.errorList(user.getErrors('fields[btw]')) }}

**Tags:** matrix, form, field, blocks

---

## 1 answers

### Answer by username_1 on 2022-07-20. Score: 0 | Accepted answer

As per the documentation, you need to include the sortOrder parameter to save multiple blocks. Include three hidden fields to pass the three new block IDs (new1, new2, new3) as a sortOrder array and the field should save successfully.




By the way, this line is not doing anything and might mess something up:

> **Comments:**
> **username_0**: Hi, thanks for your answer. I have added the code which is not showing any fields when a user completest the form.  
> **username_1**: @aren Make sure to check the `network` tab in your devtools to see if the request contains the correct payload and what response you're getting. Also, have you checked if the users in question have the required permission to update this entry? Check the logs as well to see if you're getting any errors.  
> **username_0**: I'm not getting any errors, I have assigned all the rights to the user to test but in the logs I don't find the field either.  
> **username_0**: Okay I got it somehow working by adding this line (<input type="hidden" name="fields[deviceManagement]"/>) only one  

---

