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):
<div class="matrixblock" data-id="new1">
<input type="hidden" name="fields[deviceManagement]"/>
<input type="hidden" name="fields[deviceManagement][new1][type]" value="device">
<input type="hidden" name="fields[deviceManagement][new1][enabled]" value="1">
<input type="hidden" name="fields[deviceManagement][new1][fields][macadres]" value="">
<input type="hidden" name="fields[deviceManagement][new1][fields][serial]" value="">
<input type="hidden" name="fields[deviceManagement][new1][fields][webkey]" value="">
</div>
<div class="matrixblock" data-id="new2">
<input type="hidden" name="fields[deviceManagement]"/>
<input type="hidden" name="fields[deviceManagement][new2][type]" value="device">
<input type="hidden" name="fields[deviceManagement][new2][enabled]" value="1">
<input type="hidden" name="fields[deviceManagement][new2][fields][macadres]" value="">
<input type="hidden" name="fields[deviceManagement][new2][fields][serial]" value="">
<input type="hidden" name="fields[deviceManagement][new2][fields][webkey]" value="">
</div>
<div class="matrixblock" data-id="new3">
<input type="hidden" name="fields[deviceManagement]"/>
<input type="hidden" name="fields[deviceManagement][new3][type]" value="device">
<input type="hidden" name="fields[deviceManagement][new3][enabled]" value="1">
<input type="hidden" name="fields[deviceManagement][new3][fields][macadres]" value="">
<input type="hidden" name="fields[deviceManagement][new3][fields][serial]" value="">
<input type="hidden" name="fields[deviceManagement][new3][fields][webkey]" value="">
</div>
the form(register.twig):
<form class="c-forms" method="post" accept-charset="UTF-8" id="19898981">
{% set page = craft.entries.section('login').one() %}
{{ csrfInput() }}
{{ actionInput('users/save-user') }}
{{ redirectInput(page.url) }}
{% include "_components/hidden-devices.twig" %}
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-xl-4 col-xxl-4">
<label class="c-forms__label" for="firstName">{{ entry.registerVoornaamLabel }}</label>
<input class="c-forms__input" class="form-control" type="text" id="firstName" name="firstName" placeholder="{{ entry.registerVoornaamPlaceholder }}" autocomplete="given-name" required>
{{ user ? _self.errorList(user.getErrors('firstName')) }}
<label class="c-forms__label" for="bedrijf">{{ entry.registerCompanyLabel }}</label>
<input class="c-forms__input" type="text" class="form-control" id="bedrijf" name="fields[bedrijf]" placeholder="{{ entry.registerCompanyPlaceholder }}" required>
{{ user ? _self.errorList(user.getErrors('fields[bedrijf]')) }}
<label class="c-forms__label" for="btw">{{ entry.registerBtwLabel }}</label>
<input class="c-forms__input" type="text" class="form-control" id="btw" name="fields[btw]" placeholder="{{ entry.registerBtwPlaceholder }}" required>
{{ user ? _self.errorList(user.getErrors('fields[btw]')) }}
</div>
</div>
</div>
</form>