1

I have a channel where I would like admin to be able to create entries and then anonymous users would be able to add rows to a grid field. I do not want the users to be able to see existing rows(if they exist), just add.

I thought I would be able to get the total rows, and with the Simple Math plugin, make Channel Form ready to add a new row.

<input class="input-block-level" type="text" name="field_id_44[rows][new_row_{exp:simple_math calculate="{shipping_quotes:total_rows} + 1" decimal_places="0"}][col_id_6]" value="">

Which actually works as expected

<input class="input-block-level" type="text" name="field_id_44[rows][new_row_2][col_id_6]" value=""

So [new_row_2] outputs as "2" because in this case there is already an existing row. This works no matter how many rows I add. If the entry has 3 rows in this grid field, it outputs [new_row_4]... as expected.

But this unfortunately doesn't translate when submitting the form. Submitting just replaces the existing row(#1), so I think I am misunderstanding how to add new rows via Channel Form.

So long story short, how do I add rows to a grid field via channel form.

0

This looks to be a duplicate of this : Adding New Grid Entries With Channel:Form

(you can use the same logic while switching Matrix with Grid, Or Channel form with SafeCracker Form)

Check out that question and my answer, it basically deals with what you're asking.

In short what you need to do is make sure you have the previously set rows in the Channel form as hidden elements. When you sumbit the channel entry form it takes your grid/matrix values in their entirety and saved them as the field value, it does not append them. So as you see, you will need to add the existing values to the form, then add your new values, and submit the whole lot!

5
  • I saw that solution. It's just not possible for us to output the other rows(even if hidden) as users must not see what other users have entered. There's gotta be another way. Jul 9 '15 at 21:13
  • Ahh, ok, sorry I didn't realise your requirement. I do like a challange! well there is another way. I'll try to write up another solution for you later today, but in essance what I would do is construct the entry form manually, process the posted stuff ourselves, load the existing entries server side after post (so no reveal) and save it all using the Channel Entries API
    – Blatant
    Jul 10 '15 at 10:17
  • Was about to comment again. I found a solution, but it did not work with the grid field. I had to change the field to a Matrix and use the solution here. bluefishds.com/blog/article/… Jul 10 '15 at 11:07
  • Ahh great, glad you got it working. You could perhaps move your link to a new answer so you can mark it as correct and it'll be easier for others to work with it. I see that for the matrix thereis one hidden filed (<input type="hidden" name="cf_registration_add_attendees[row_order][]" value="row_new_0">) which is ehats cluing Matrix into accepting a new row without existing values. You're right in oyur findings, Grid does not support this so for Grid your stuck with using the channel form API or repeating the previous values. Glad you're sorted thought!
    – Blatant
    Jul 10 '15 at 14:37
  • This may be similar to your solution, but, I had a sililar scenario returning freeform replys to only the user that sent them (from the same form) for this I had a field that stored that users member_id and then on viewing the form replys if the logged_in_member_id matched the stored member_id then that entry would display.
    – sheferd
    Dec 8 '15 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.