1

I am trying to save comments using the core method "entries/saveEntry", but every time I submit the form the last comment is overwritten, is there a simple way of submitting this information to insert instead of update all the comments?

I the form working in that it relates a comment to an entry using the following form:

<form method="post" accept-charset="UTF-8">
    <input type="hidden" name="action" value="entries/saveEntry">
    {{ getCsrfInput() }}
    <input type="hidden" name="entryId" value="{{ entry.id }}">
    <input type="hidden" name="fields[usercomments][new1][type]" value="comments">
    <input type="text" name="fields[usercomments][new1][fields][commentuser]" value="">
    <input type="text" name="fields[usercomments][new1][fields][commenttext]" value="">
    <input type="submit" value="Publish">
</form>

I just dont get why the comments are being overwritten and how to just insert a new entry.

1
  • 2
    You're saving it with the same entry ID each time. There's another question on how to do comments related to an entry: "Creating comments via a related section". I think <s>Douglas' answer does</s> both answers do a great job explaining on how to do this properly.
    – carlcs
    Mar 4 '15 at 10:47
1

You'll have to resubmit all the previous comments through hidden fields aswell. You can achieve this by looping through them in the form, and put their values into hidden inputs.

1

As @carlcs mentioned, it's likely due to the way you're saving the ID...

<input type="hidden" name="entryId" value="{{ entry.id }}">

I would omit this line to ensure you save a new comment each time.

If you actually want to have a form that allows editing of existing comments, then you need to pass in the ID of the comment, not the ID of the parent entry.

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.