Working with Channel form, I have encountered some problems when working with multiple Matrix fields in a single edit form.
[EE v2.7.3 and Matrix 2.5.10]
When I work with "native" channel form fields
{field:field_name}
everything works fine and I can edit all matrix fields and post data.When I try to use the "custom code" below (example on MetaQ), only the last Matrix field is working. When viewing source, the problem seems to be that all matrix fields before the last one get the
{row_id}
and the number of rows of the last Matrix in the form (the one with the highest order value in the field group they both belong to).
The template :
<!DOCTYPE html >
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="fr"> <!--<![endif]-->
<head>
</head>
<body>
{exp:channel:form channel="test" entry_id="34"}
<label for="title">Title</label>
<input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" onkeyup="liveUrlTitle();">
<label for="url_title">URL Title</label>
<input type="text" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50">
{cf_couleur}
<div class="field"><!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_couleur[row_order][]" value="row_id_{row_id}" />
<input type="text" id="cf_couleur" name="cf_couleur[row_id_{row_id}][col_id_26]" value="{couleur1}">
</div>
{/cf_couleur}
{cf_forme}
<div class="field"><!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_forme[row_order][]" value="row_id_{row_id}" />
<input type="text" id="cf_forme" name="cf_forme[row_id_{row_id}][col_id_27]" value="{form1}">
</div>
{/cf_forme}
{/exp:channel:form}
</body>
</html>
The matrix generated in the browser :
<div class="field">
<!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_couleur[row_order][]" value="row_id_184" />
<input type="text" id="cf_couleur" name="cf_couleur[row_id_184][col_id_26]" value="{couleur1}">
</div>
<div class="field">
<!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_couleur[row_order][]" value="row_id_185" />
<input type="text" id="cf_couleur" name="cf_couleur[row_id_185][col_id_26]" value="{couleur1}">
</div>
<div class="field">
<!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_forme[row_order][]" value="row_id_184" />
<input type="text" id="cf_forme" name="cf_forme[row_id_184][col_id_27]" value="cube">
</div>
<div class="field">
<!--THIS IS A MATRIX ROW-->
<input type="hidden" name="cf_forme[row_order][]" value="row_id_185" />
<input type="text" id="cf_forme" name="cf_forme[row_id_185][col_id_27]" value="carrer">
</div>
The code above is a very simple form that I have done to try to narrow down the problem. On channel ad two matrix fields with just 1 text field in each of them.
I have compared my custom code and the code generated by the native channel form field and cannot see any difference in the field names.
I have then simply put every matrix field in their own embeds, passing the ID of the entry I am editing to the {exp:channel:entries}
loop around each of them. That works fine, even with my custom code.
I would very much like to understand what is happening here, as I would rather have everything in the form and not make use of embeds.