I've been experimenting with ExpressionEngine 2.7.0, attempting to replace my use of Matrix with Grid and updating my Safecracker forms with Channel Forms.
Currently, I have a template where users are able to create a channel entry in a SafeCracker form, which includes populating the first row in a Matrix field within that entry.
I'd like to replace that with a template where users are able to create an entry using a Channel Form and populate a row in a Grid field. I've successfully changed it to a Channel Form, but can't for the life of me figure out how to populate a Grid field. I'll share the code I was previously using:
{exp:safecracker channel="routine" return="" json="yes" rules:field_id_3[row_new_0][col_id_1]="valid_ee_date"}
<input name="RET" type="hidden" value="/" />
<input name="title" type="hidden" value="New Routine" />
<input name="routine_catalyst" type="text" />
<input name="routine_reaction" type="text" />
<input type="hidden" name="field_id_3[row_order][]" value="row_new_0" />
<input type="hidden" name="field_id_3[row_new_0][col_id_1]" value="{entry_date}" />
<select style="display: none" name="field_id_3[row_new_0][col_id_2]">
<option value="n" selected="">NO</option>
<option value="y">YES</option>
</select>
<select name="category[]" id="routine_category" size="4" multiple="multiple" style="display: none;">
{categories}
<option value="{category_id}"{selected}>{category_name}</option>
{/categories}
</select>
{/exp:safecracker}
and what I currently have below
{exp:channel:form
channel="routine"
return=""
json="yes"
}
<input name="RET" type="hidden" value="/" />
<input name="title" type="hidden" value="New Routine" />
<input name="routine_catalyst" type="text" />
<input name="routine_reaction" type="text" />
<input type="text" name="routine_occurence[row_order][]" value="row_new_0" />
<input type="" name="routine_occurence:date" value="{entry_date}" />
<select style="" name="routine_occurence:complete">
<option value="false" selected="">false</option>
<option value="true">true</option>
</select>
<select name="category[]" id="routine_category" size="4" multiple="multiple">
{categories}
<option value="{category_id}"{selected}>{category_name}</option>
{/categories}
</select>
<input type="submit" value="submit" />
{/exp:channel:form}
I know it's still new, but I was wondering whether anyone had had any success with this? The docs are pretty lacking in the area at the moment.
EDIT: I should add that when I use the above code, I receive PHP errors with the message:
Severity: Notice
Message: Undefined offset: 0
Filename: libraries/Grid_lib.php
Line Number: 238
And the entry is created, without the Grid row being entered
EDIT2: Solution below