I'm trying to rearrange the matrix block order using a frontend form.
- If I use JavaScript to change the order of inputs in the DOM will this change the order in the backend after form submission?
- How do you include the correct value for image fields, is this using the image id?
I have a reduced test case of what I came up with below, anyone see where I'm going wrong?
<form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
{{ getCsrfInput() }}
<input type="hidden" name="action" value="entries/saveEntry">
<input type="hidden" name="redirect" value="viewentry/{slug}">
<input type="hidden" name="entryId" value="{{ entry.id }}">
<input type="hidden" name="fields[galleryBlock]" />
{% for block in entry.galleryBlock %}
{% switch slide.type %}
{% case 'landscape' %}
{# block 1 #}
{% set image = block.image[0] ?? null %}
<input type="hidden" name="fields[galleryBlock][{{ block.id }}][landscape]" value="{{ image.id }}">
<input type="hidden" name="fields[galleryBlock][{{ block.id }}][enabled]" value="1">
{% case 'portrait' %}
{# block 2 #}
{% set image = block.image[0] ?? null %}
<input type="hidden" name="fields[galleryBlock][{{ block.id }}][portrait]" value="{{ image.id }}">
<input type="hidden" name="fields[galleryBlock][{{ block.id }}][enabled]" value="1">
{% endswitch %}
{% endfor %}