1

I have Notification entry with sendTo field and nViewed matrix:
- viewedBy = Users field, limit of 1
- viewedDateTime = Plain Text

User's don't see whole front end form, just a 'Mark as Read' link. The link uses js to populate viewedDateTime and submit form. My form:

<form id="update-{{ msg.id }}" method="post" accept-charset="UTF-8">
   {{ csrfInput() }}
   <input type="hidden" name="action" value="entries/save-entry" />
   <input type="hidden" name="redirect" value="{{ theredirect }}" />
   <input type="hidden" name="sectionId" value="{{ msg.section.id }}" />
   <input type="hidden" name="entryId" value="{{ msg.id }}" />
   <input type="hidden" name="fields[nViewed]" />
   <input type="hidden" name="fields[nViewed][new1][type]" value="viewed" />
   <input type="hidden" name="fields[nViewed][new1][enabled]" value="1" />
   <input type="hidden" name="fields[nViewed][new1][fields][viewedBy][]" value="{{ currentUser.id }}" />
   <input type="hidden" name="fields[nViewed][new1][fields][viewedDateTime]" value="" />
   <button type="submit" class="tx-11 btn bd-0">Mark as read</button>
</form>

When the first user from sentTo clicks the 'Mark as Read' link, they get added to the matrix. All good.

When the second user from sentTo (testing on a different browser) clicks the 'Mark as Read' link it overwrites the first users row instead of adding another row to matrix.

I've also tried using field name="fields[nViewed][new{{ currentUser.id }}]... to make them unique but still overwrites.

What am I missing?
Amanda

1 Answer 1

2

According to the craft cms docs

To show a “New Block” form, first come up with a temporary ID for the block, prefixed with new:. For example, new:1, new:2, etc.

so, you need to you use prefix new: with the colon is a must.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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