I’m using latest EE 7.5.1
I need to create a form on the frontend that users can edit their entry… in my custom users channel, I have a grid field that I need to display in the channel form so they can edit those fields as well as regular text fields.
I’ve confirmed i can display the grid fields from exp:channel:entries but it doesn’t seem to work in a exp:channel:form with a specific entry_id
I even created a new grid field just to test in case something got corrupt in my original one, and it still gives DB errors in the browser.
{test_grid}
{test_grid:my_name}
{/test_grid}
Exception Caught
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘test.exp_channel_grid_field_’ doesn’t exist:
SELECT * FROM (exp_channel_grid_field_
) WHERE entry_id
IN (21) AND fluid_field_data_id
= 0 ORDER BY row_order
asc
ee/legacy/database/drivers/mysqli/mysqli_connection.php:146
yes. I’ve tried a bunch of combos like
{test_grid:my_name} or {field:my_name}
and it just spits that out on the page, not the value.
I need to loop thru all rows of the grid in this channel form, so i’m gathering i need to put them in a grid pair tag like this, but page breaks anytime that’s done when inside channel form {test_grid}{/test_grid}
I just tested on mine and
{field:my_grid}
{error:my_grid}
Works as expected. But I suspect I may not fully understand what you’re doing. Can you simply the template down as much as possible and then put a copy up here? Like- everything inside the channel form tags- including opening/closing tag. Really simplified.
i can dummy it down to this and it still won’t work. I’ve confirmed the embed:entry_id works as i can pull other text fields from that entry.
there will be over 10 rows from this grid i need to loop thru. I even go into CMS and find the grid field and click it so it generates the code i should be using… that’s what breaks page
{exp:channel:form channel=”users” id=”some-id” entry_id=”{embed:entry_id}” include_jquery=”yes” return=”some-url” } {if no_results} Error retrieving user ID: {embed:entry_id} {/if}
{field:my_name}
{test_grid}
{test_grid:my_name}
{/test_grid}
{/exp:channel:form}
Ah- try
{exp:channel:form channel=”users” id=”some-id” entry_id=”{embed:entry_id}” include_jquery=”yes” return=”some-url” } {if no_results} Error retrieving user ID: {embed:entry_id} {/if}
{field:test_grid}
{/exp:channel:form}
Any luck? If there’s a problem, drop the id parameter in the form.
ahh, ok that seems to work and spits out it’s own markup for all the rows thank you! Is there any way I can have control over these so as I can loop thru each grid row and can have custom markup for my design?
after looking at the DOM of what it spit out for my real grid, it seems the input on my first column in the grid has the name=”week_1_picks[rows][row_id_18][col_id_75]”.
Is there any way to reference row_id_18 and col_id_75 in a more readable manner in my custom input fields?
I do a lot of this, particularly for editing grid rows.
Ultimately, if you’re generating the grid fields yourself, you have to have EVERY row, and EVERY column for each, in the DOM - even if its not something you want to change, or allow the user to change. Without all the existing rows, you’ll lose all the grid data.
{grid_field}
<input type="text" name="grid_field[rows][row_id_{grid_field:row_id}][col_id_44]" value="{grid_field:my_col_44_name}" readonly>
<input type="hidden" name="grid_field[rows][row_id_{grid_field:row_id}][col_id_46]" value="{grid_field:my_col_46_name}" readonly>
<input type="text" name="grid_field[rows][row_id_{grid_field:row_id}][col_id_48]" value="{grid_field:my_col_48_name}" readonly>
<input type="hidden" name="grid_field[rows][row_id_{grid_field:row_id}][col_id_49]" value="{grid_field:my_col_49_name}">
{/grid_field}
I also use flagging (my col_id_49 is actually a toggle in this example) which I will set on save using javascript, to basically prevent further editing of that row. In that case, I then need to run the grid field tag pair twice inside the channel form; once with a search param for col_id_49 to be 0 (editable), and again where col_id_49 is 1 (no longer editable, and hence all fields hidden or readonly or whatever). Might not apply in your use case, but this is how you get granular control of the individual field data in grids on the front end.
For generating a new entry, it depends if you are always using a fixed number of rows - in which case, hardcode them - or, allowing the user to dynamically set the number of rows. In the latter case, I have Javascript setup to basically replicate the inputs needed for an entire row, and auto-increment the new_row_X part of the field names as needed:
<input type="text" name="grid_field[rows][new_row_1][col_id_44]" value="">
<input type="hidden" name="grid_field[rows][new_row_1][col_id_46]" value="set value">
<input type="text" name="grid_field[rows][new_row_1][col_id_48]" value="">
<input type="hidden" name="grid_field[rows][new_row_1][col_id_49]" value="another set value">
The only other use case is adding more grid rows to an existing grid, which I’ve not done for a while but iirc, it still starts from [new_row_1] each time… but don’t quote me on that!
ya, I’ve noticed i was losing data when i was just putting only the fields i wanted to update. Kind of a pain you have to have every row and column but definitely good to know if using channel form. If you update fields with PHP using the ee()->db->then you don’t need to do every field at least.
In case this helps someone, I ended up creating a PHP array at the top of my template that has all my col_id’s for that grid (by looking them up individually in the cms) so i could at least reference those like below. I also found putting a data attribute with the field name was super helpful so when i inspected the dom i could tell what each hidden input field was for.
<input type="hidden" name="grid_field[rows][row_id_{grid_field:row_id}][col_id_<?php echo $col_ids['my_field_name']; ?>]" value="some value" data-field="my_field_name" />
I just wish there was an easy way to reference grid fields. EE needs to do their own mapping or something so we can reference the actual grid field name rather than having to look up every col_id and what not.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.